Re: Compiling python from soruce vs RPM ?
howa wrote: > I have compiled python 2.5 from source > > i.e. > > ./configure > make > make install > > > but when i try to install another package require python, seems it > can't regonize python... > > e.g.. > > > /usr/bin/python is needed by xyz Does "/usr/bin/python" exist ? Why haven't you installed via rpm ? H. -- http://mail.python.org/mailman/listinfo/python-list
Re: Future Python Gui?
[EMAIL PROTECTED] wrote: > If this were just a tool for me, it wouldn't matter. My concern is > distribution. If anybody who wants to run my software then they also > have to go through all the trouble to install these extensions, none > of which seem to have decent instructions. I'm an old-time hack and I > have trouble getting them to work. A simple user won't have a chance! > > If Python doesn't declare an official Gui system, then it'll be > fragmented, inconsistent, and unsupportable. I guess that's why Tkinter, despite its primitive look, has made its way into the Python-distribution and I think, for the same reason it will stay there, until it can be replaced by something similar consistent. H. -- http://mail.python.org/mailman/listinfo/python-list
Re: Generate report containing pdf or ps figures?
Grant Edwards wrote: > On 2007-04-23, Kjell Magne Fauske <[EMAIL PROTECTED]> wrote: > >>> Is there a PDF generation library that can place EPS or PDF >>> figures on a page? What about http://pybrary.net/pyPdf/ It does some very interesting things. But I'm not really sure, if it does what you're after. At least it can merge one page onto another. H. -- http://mail.python.org/mailman/listinfo/python-list
Re: key detect
Alex Taslab wrote: > Hi everybody, does anyone know how to detect a key press from a > keyboard. Well I do know how to do that, but i need to detect just one > press and ignore the others. I mean, my program checks an input from the > outside (a sensor) and i emulate that signal as a keypress, but the > sensor doesn`t send the signal as a unique pulse y just keeps sending > signal during some seconds, so that is like to be pressing one key for a > period of time. How can i take that first press of a key and ignore the > others? I am using pygtk. thanks everybody! Perhaps you could emulate the sensor-signal as something else than a keypress, perhaps pipe the event-data into some temporary file or so. H. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using python with MySQL
HMS Surprise wrote:
> Greetings,
>
> I need to peform some simple queries via MySQL. Searching the list I
> see that folks are accessing it with python. I am very new to python
> and pretty new to MySQL too. Would appreciate it if you could point me
> to some documentation for accessing MySQL via python. Something of the
> "Python and MySQL for Dummies" caliber would be about my speed, but of
> course I will be thankful for anything offered.
>
> Thanks,
>
> jvh
There's even another approach:
If you're on Linux, Qt3 may be available. Install its Python-bindings. Given
a database "MyDatabase", with password "MyPassword" for user "root" and
inside the database a table "MyTable", you can then do something like this:
#!/usr/bin/env python
from qt import *
import sys
from qtsql import QSqlDatabase, QSqlQuery
app = QApplication(sys.argv)
DB = QSqlDatabase("QMYSQL3", "MyDatabase", app)
DB.setDatabaseName("MyDatabase")
DB.setUserName("root")
DB.setPassword("MyPassword")
DB.setHostName("localhost")
DB.open()
c = DB.execStatement("select * from MyTable")
while c.next():
print c.value(0).toString()
print c.value(1).toString()
print c.value(2).toString()
print c.value(3).toString()
c.first()
c2 = DB.execStatement("select count(*) from MyTable")
c2.next()
print c2.value(0).toString()
Some further documentation:
http://www.arl.hpc.mil/ice/Manuals/PyQt/t1.html
http://doc.trolltech.com/4.2/database.html
H.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Using python with MySQL
hlubenow wrote: > There's even another approach: ... On the other hand you may be better off with the "mysql-python"-module. Anyway, here's a nice overview over the most commonly used MySQL-commands (The commands should speak for themselves, even if the explanations are in German): http://www.linux-club.de/ftopic49585.html H. -- http://mail.python.org/mailman/listinfo/python-list
Re: Mouse click in python
Synt4x wrote: > I'm creating a webcam user interface (to control google earth through > my webcam) and I still can't find a good example to how to control the > mouse to "click and drag" (not just click and release). Pygame: http://www.pygame.org/ http://www.pygame.org/docs/ref/mouse.html provides event-control including mouse-event-control. Mainly it's intended for games, but it should work for other projects like yours too. HTH H. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pygame Q (linux) beginner
enquiring mind wrote: > Running 2.4.1 Python (learning) > Running SUSE Linux 10 > > At Chapter 5 is where the Pygame module is > introduced so I have a little time before I have to figure out what I > have to download and install. Are you asking for advice how to install pygame on SuSE 10 ? Well, that's easy: python-pygamerpm comes with SuSE. Just install it with YaST2; the additional packages it needs (like libSDL) are installed automatically then. So you don't have to download any packages from www.pygame.org. Another hint: If sound in pygame doesn't work, try export SDL_AUDIODRIVER=alsa right before starting your script. H. -- http://mail.python.org/mailman/listinfo/python-list
Re: How can i compare a string which is non null and empty
[EMAIL PROTECTED] wrote:
>
> Hi,
>
> how can i compare a string which is non null and empty?
>
>
> i look thru the string methods here, but cant find one which does it?
>
> http://docs.python.org/lib/string-methods.html#string-methods
>
> In java,I do this:
> if (str != null) && (!str.equals(""))
>
> how can i do that in python?
What about
if str != "":
pass
?
--
http://mail.python.org/mailman/listinfo/python-list
Re: Pygame Q (linux) beginner
enquiring mind wrote: > Thank you very much. A buddy installed SUSE 10 in Dec. for me so I > shall ask him to look for rpm which I understand from your post includes > pygame. You have no idea how much I appreciate your information. My pleasure. By the way: It would be quite easy to install it yourself, too. Here's how: If you use KDE, click on the start-menu-button and go to System/ControlCenter(YaST) there. You're asked for your root-password. Enter it and YaST2 appears (it is SuSE's graphical installation tool). Click on Software/Software installation. After a while a search-field appears. Enter "python-pygame" there and click on "search". It should be shown in the right window. Click on the rectangle left of it and press "keep changes" (or "ok" or so) in the right corner at the bottom. You should be asked to insert some CD/DVD then. Do it, wait a while and pygame should have been installed. It is really not much more difficult than on Windows. See you H. -- http://mail.python.org/mailman/listinfo/python-list
Re: way to extract only the message from pop3
[EMAIL PROTECTED] wrote: > I found a tutorial on parsing email that should help you: > > http://www.devshed.com/c/a/Python/Python-Email-Libraries-SMTP-and-Email-Parsing/ > > Also see the email module: > > http://www.python.org/doc/2.3.5/lib/module-email.html > > Mike Well, I couldn't work with that stuff, especially with that tutorial, some time ago. It worked better, when I took a look at the code, user "rogen" wrote in his first posting here: http://www.python-forum.de/topic-7507.html It's really not beautiful code, but as soon as you understand, what he does, you're almost there. See You H. -- http://mail.python.org/mailman/listinfo/python-list
Re: way to extract only the message from pop3
flit wrote:
> Hello All,
>
> Using poplib in python I can extract only the headers using the .top,
> there is a way to extract only the message text without the headers?
As mentioned before, you should use module "email":
#!/usr/bin/env python
import poplib
import email
import os
import sys
import string
PROVIDER = "pop.YourMailProvider.de"
USER = "YourUserName"
PASSWORD = "YourPassword"
try:
client = poplib.POP3(PROVIDER)
except:
print "Error: Provider not found."
sys.exit(1)
client.user(USER)
client.pass_(PASSWORD)
nrof_mails = len(client.list()[1])
for i in range(nrof_mails):
lines = client.retr(i + 1)[1]
mailstring = string.join(lines, "\n")
blockit = 0
msg = email.message_from_string(mailstring)
for part in msg.walk():
if part.get_content_maintype() == "text" and blockit == 0:
blockit = 1
mycontent = part.get_payload()
mycontent = mycontent.decode("quopri_codec")
print mycontent
print
client.quit()
See You
H.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Looping issues
[EMAIL PROTECTED] wrote:
> On Apr 5, 2:18 pm, "anglozaxxon" <[EMAIL PROTECTED]> wrote:
>> On Apr 5, 2:01 pm, [EMAIL PROTECTED] wrote:
>>
>>
>>
>> > What I am trying to do is compare two files to each other.
>>
>> > If the 2nd file contains the same line the first file contains, I want
>> > to print it. I wrote up the following code:
>>
>> > correct_settings = open("C:\Python25\Scripts\Output
>> > \correct_settings.txt","r")
>> > current_settings = open("C:\Python25\Scripts\Output\output.txt","r")
>>
>> > for line in correct_settings:
>> > for val in current_settings:
>> > if val == line:
>> > print line + " found."
>>
>> > correct_settings.close()
>> > current_settings.close()
>>
>> > For some reason this only looks at the first line of the
>> > correct_settings.txt file. Any ideas as to how i can loop through each
>> > line of the correct_settings file instead of just looking at the first?
>>
>> Instead of "for line in correct_settings", try "for line in
>> correct_settings.readlines()".
>
> That Still didnt fix it. Same output
Try this:
correct_settings = file("C:\Python25\Scripts\Output\correct_settings.txt",
"r")
current_settings = file("C:\Python25\Scripts\Output\output.txt", "r")
a = correct_settings.readlines()
b = current_settings.readlines()
correct_settings.close()
current_settings.close()
for line in a:
for val in b:
if val == line:
print line + " found."
--
http://mail.python.org/mailman/listinfo/python-list
Re: Extract zip file from email attachment
erikcw wrote:
> Hi all,
>
> I'm trying to extract zip file (containing an xml file) from an email
> so I can process it. But I'm running up against some brick walls.
> I've been googling and reading all afternoon, and can't seem to figure
> it out.
>
> Here is what I have so far.
>
> p = POP3("mail.server.com")
> print p.getwelcome()
> # authentication, etc.
> print p.user("USER")
> print p.pass_("PASS")
> print "This mailbox has %d messages, totaling %d bytes." % p.stat()
> msg_list = p.list()
> print msg_list
> if not msg_list[0].startswith('+OK'):
> # Handle error
> exit(1)
>
> for msg in msg_list[1]:
> msg_num, _ = msg.split()
> resp = p.retr(msg_num)
> if resp[0].startswith('+OK'):
> #print resp, '===\n'
> #extract message body and attachment.
> parsed_msg = email.message_from_string('\n'.join(resp[1]))
> payload= parsed_msg.get_payload(decode=True)
> print payload #doesn't seem to work
> else:
> pass# Deal with error retrieving message.
>
> How do I:
> a) retrieve the body of the email into a string so I can do some
> processing? (I can get at the header attributes without any trouble)
> b) retrieve the zip file attachment, and unzip into a string for xml
> processing?
>
> Thanks so much for your help!
> Erik
Hi,
some weeks ago I wrote some code to extract attachments from emails.
It's not that long, so maybe it could be of help for you:
---
#!/usr/bin/env python
import poplib
import email
import os
import sys
import string
#
# attsave.py
# Check emails at PROVIDER for attachments and save them to SAVEDIR.
#
PROVIDER = "pop.YourMailProvider.de"
USER = "YourUserName"
PASSWORD = "YourPassword"
SAVEDIR = "/home/YourUserDirectory"
def saveAttachment(mstring):
filenames = []
attachedcontents = []
msg = email.message_from_string(mstring)
for part in msg.walk():
fn = part.get_filename()
if fn <> None:
filenames.append(fn)
attachedcontents.append(part.get_payload())
for i in range(len(filenames)):
fp = file(SAVEDIR + "/" + filenames[i], "wb")
fp.write(attachedcontents[i])
print 'Found and saved attachment "' + filenames[i] + '".'
fp.close()
try:
client = poplib.POP3(PROVIDER)
except:
print "Error: Provider not found."
sys.exit(1)
client.user(USER)
client.pass_(PASSWORD)
anzahl_mails = len(client.list()[1])
for i in range(anzahl_mails):
lines = client.retr(i + 1)[1]
mailstring = string.join(lines, "\n")
saveAttachment(mailstring)
client.quit()
---
See you
H.
--
http://mail.python.org/mailman/listinfo/python-list
Hide the python-script from user
Hi, recently there was a thread about hiding the python-script from the user. The OP could use http://freshmeat.net/projects/pyobfuscate/ H. -- http://mail.python.org/mailman/listinfo/python-list
Re: Hide the python-script from user
ts-dev wrote: > On Apr 6, 3:19 pm, hlubenow <[EMAIL PROTECTED]> wrote: >> recently there was a thread about hiding the python-script from the user. >> The OP could use > > Interesting - thanks Well, testing it, it doesn't seem to work very well ... It seems, Python-code is rather difficult to obfuscate, probably because of its clear syntax and indentations. Here's yet another approach: http://pythonhacker.is-a-geek.net/my_programs/pyfuscate/pyfuscate-0.1.zip/view H. -- http://mail.python.org/mailman/listinfo/python-list
Re: Hide the python-script from user
hlubenow wrote:
> ts-dev wrote:
>
>> On Apr 6, 3:19 pm, hlubenow <[EMAIL PROTECTED]> wrote:
>>> recently there was a thread about hiding the python-script from the
>>> user. The OP could use
>>
>> Interesting - thanks
>
> Well, testing it, it doesn't seem to work very well ...
>
> It seems, Python-code is rather difficult to obfuscate, probably because
> of its clear syntax and indentations. Here's yet another approach:
>
>
http://pythonhacker.is-a-geek.net/my_programs/pyfuscate/pyfuscate-0.1.zip/view
>
> H.
That didn't work very well either :(.
Ok, but now I can offer a real secure solution:
You can have real encryption in Python using this modules:
http://www.amk.ca/files/python/crypto/pycrypto-2.0.1.tar.gz
and
http://sourceforge.net/projects/yawpycrypto
Below I post a code-example that I've written some time ago. With it,
encrypting text is rather easy.
Then you have to program a start-script, that reads in your script and the
decryption-key. The decryption-key must be encrypted too. Such a encrypted
key can be generated by the modules if you don't pass a password to my
function "doEncrypt(). The decryption-key must then be hidden somewhere
within the encrypted program-script. That's because, if the user knows
where to find the key, he can decrypt the program-script.
If your start-script is written, everything should work automatically, one
shouldn't nearly notice the decryption-process.
Ok, here's my example code, how to encrypt and decrypt some text with the
modules:
#!/usr/bin/env python
import os
import sys
import base64
from yawPyCrypto.Cipher import DecryptCipher, EncryptCipher
from yawPyCrypto.Cipher import ZipDecryptCipher, ZipEncryptCipher
from yawPyCrypto.Constants import CIPHER_BLOWFISH, MODE_CBC
def doEncrypt(text, passw = None):
e = EncryptCipher(passw, CIPHER_BLOWFISH, MODE_CBC)
e.feed(text)
e.finish()
encryptedtext = e.data
if passw != None:
passwr = passw
else:
passwr = e.password
a = (encryptedtext, passwr)
return a
def doDecrypt(encryptedtext, passw):
d = DecryptCipher(passw)
d.feed(encryptedtext)
d.finish()
decoded = (d.data)
return decoded
# Calling the encryption routine.
# If you just pass the text to encrypt, a password is generated:
a = doEncrypt("For your eyes only !", "Melina")
# Just trying to clean the screen:
if sys.platform == "win32":
os.system("cls")
else:
os.system("clear")
print
print "Hello !"
print
print "I just encrypted some text. It looks like this now:"
print
print base64.b64encode(a[0])
print
print 'Please notice, that I just encoded the text once more using
"base64.b64encode()" to make it printable.'
print
print "The password for decryption is: "
print
print base64.b64encode(a[1])
print
print "Let's decrypt again (the original password must be passed without
b64encoding):"
print
print doDecrypt(a[0], a[1])
print
See you
H.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Hide the python-script from user
hlubenow wrote:
> hlubenow wrote:
>
>> ts-dev wrote:
>>
>>> On Apr 6, 3:19 pm, hlubenow <[EMAIL PROTECTED]> wrote:
>>>> recently there was a thread about hiding the python-script from the
>>>> user. The OP could use
>>>
>>> Interesting - thanks
>>
>> Well, testing it, it doesn't seem to work very well ...
>>
>> It seems, Python-code is rather difficult to obfuscate, probably because
>> of its clear syntax and indentations. Here's yet another approach:
>>
>>
>
http://pythonhacker.is-a-geek.net/my_programs/pyfuscate/pyfuscate-0.1.zip/view
>>
>> H.
>
> That didn't work very well either :(.
>
> Ok, but now I can offer a real secure solution:
>
> You can have real encryption in Python using this modules:
>
>
> http://www.amk.ca/files/python/crypto/pycrypto-2.0.1.tar.gz
>
> and
>
> http://sourceforge.net/projects/yawpycrypto
>
> Below I post a code-example that I've written some time ago. With it,
> encrypting text is rather easy.
>
> Then you have to program a start-script, that reads in your script and the
> decryption-key. The decryption-key must be encrypted too. Such a encrypted
> key can be generated by the modules if you don't pass a password to my
> function "doEncrypt(). The decryption-key must then be hidden somewhere
> within the encrypted program-script. That's because, if the user knows
> where to find the key, he can decrypt the program-script.
>
> If your start-script is written, everything should work automatically, one
> shouldn't nearly notice the decryption-process.
>
> Ok, here's my example code, how to encrypt and decrypt some text with the
> modules:
>
>
>
> #!/usr/bin/env python
>
> import os
> import sys
> import base64
>
> from yawPyCrypto.Cipher import DecryptCipher, EncryptCipher
> from yawPyCrypto.Cipher import ZipDecryptCipher, ZipEncryptCipher
> from yawPyCrypto.Constants import CIPHER_BLOWFISH, MODE_CBC
>
>
> def doEncrypt(text, passw = None):
>
> e = EncryptCipher(passw, CIPHER_BLOWFISH, MODE_CBC)
> e.feed(text)
> e.finish()
> encryptedtext = e.data
>
> if passw != None:
> passwr = passw
> else:
> passwr = e.password
>
> a = (encryptedtext, passwr)
> return a
>
>
> def doDecrypt(encryptedtext, passw):
> d = DecryptCipher(passw)
> d.feed(encryptedtext)
> d.finish()
> decoded = (d.data)
> return decoded
>
>
> # Calling the encryption routine.
> # If you just pass the text to encrypt, a password is generated:
>
> a = doEncrypt("For your eyes only !", "Melina")
>
>
> # Just trying to clean the screen:
>
> if sys.platform == "win32":
> os.system("cls")
> else:
> os.system("clear")
>
> print
> print "Hello !"
> print
> print "I just encrypted some text. It looks like this now:"
> print
>
> print base64.b64encode(a[0])
>
> print
> print 'Please notice, that I just encoded the text once more using
"base64.b64encode()" to make it printable.'
> print
> print "The password for decryption is: "
> print
> print base64.b64encode(a[1])
> print
> print "Let's decrypt again (the original password must be passed without
b64encoding):"
> print
> print doDecrypt(a[0], a[1])
> print
>
>
>
> See you
>
> H.
This still has a problem: The start-script has to know how to decrypt the
main-script and the start-script is visible, so the user can see how it
does it.
Perhaps one could obfuscate the start-script or write a C extension, that
does decrypting instead of the start-script.
This is getting rather complicated ...
H.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Can't Get Email Interface Working
Eric Price wrote:
> Hi;
> I'm writing a script that includes an email function. So I went to the
> cookbook and dug up this, and tweaked it just a bit to make it easier to
> get it to work, but it throws an error:
>
def createMail(sender, recipient, subject, html, text):
> ... import MimeWriter, mimetools, cStringIO
> ... out = cStringIO.StringIO()
> ... # txtin = cStringIO.StringIO(msg)
> ... writer = MimeWriter.MimeWriter(out)
> ... writer.addheader("From", sender)
> ... writer.addheader("To", recipient)
> ... writer.addheader("Subject", subject)
> ... writer.addheader("MIME-Version", "1.0")
> ... writer.startmultipartbody("alternative")
> ... writer.flushheaders()
> ... subpart = writer.nextpart()
> ... subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
> ... pout = subpart.startbody("text/plain", [("charset", 'us-ascii')])
> ... mimetools.encode(txtin, pout, 'quoted-printable')
> ... txtin.close()
> ... subpart = writer.nextpart()
> ... subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
> ... pout = subpart.startbody("text/html", [("charset", 'us-ascii')])
> ... mimetools.encode(htmlin, pout, 'quoted-printable')
> ... htmlin.close()
> ... writer.lastpart()
> ... msg = "test"
> ... out.close()
> ... return msg
> ...
# ---
> ... def sendMail(sender, recipient, subject, html, text):
> ... import smtplib
> ... message = createMail(sender, recipient, subject, html, text)
> ... server = smtplib.SMTP("localhost")
> ... server.sendmail(sender, recipient, message)
> ... server.quit()
> ...
if __name__=="__main__":
> ... sendMail("[EMAIL PROTECTED]", "[EMAIL PROTECTED]", "Web Stie(s)
> Down!!!", "", "text")
> ...
> Traceback (most recent call last):
> File "", line 2, in ?
> File "", line 4, in sendMail
> File "", line 10, in createMail
> File "/usr/local/lib/python2.4/MimeWriter.py", line 153, in
> startmultipartbody
> self._boundary = boundary or mimetools.choose_boundary()
> File "/usr/local/lib/python2.4/mimetools.py", line 130, in
> choose_boundary
> hostid = socket.gethostbyname(socket.gethostname())
> socket.gaierror: (8, 'hostname nor servname provided, or not known')
>
> Now, I can send email from my server no problem. In fact, I have my script
> working already...but with a shell script instead of this python code.
:lol:
> Please advise.
> TIA,
> Eric
You may want to take a look at simplemail.py:
http://gelb.bcom.at/trac/simplemail/browser/trunk/simplemail.py
that does sending mails in Python comfortably.
HTH
H.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Can't Get Email Interface Working
Eric Price wrote: > Good grief! And they call a 722-line program "simple"?! LOL! > I did what I need to do with a __one_line_shell_script__ LOL! > Naw, if I have to go through all that, I'll skip on python this time > around, thank you very much! > Eric Ok, "simplemail.py" is quite long. That's because it enables you to send attachements and deals with character encoding and so on. It is meant as a module (I didn't write it). You can use it just like that: --- from simplemail import Email Email( from_address = "[EMAIL PROTECTED]", to_address = "[EMAIL PROTECTED]", subject = "Subject", message = "Text of the message" ).send() --- That's not that much longer than a single shell-command (and it's Python :) ). "simplemail.py" has been discussed here: http://www.python-forum.de/topic-3158.html but just in German. H. -- http://mail.python.org/mailman/listinfo/python-list
Check for keypress on Linux xterm ?
Hello, I'd like to check, if a single key is pressed on a Linux xterm. This code waits for a key to be pressed and returns the character: #!/usr/bin/env python import sys import tty import termios fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) def getOneKey(): try: tty.setcbreak(sys.stdin.fileno()) ch = sys.stdin.read(1) return ord(ch) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) while True: a = chr(getOneKey()) print a My problem is, I don't want my program to wait for the keypress. I just want to check, if a key is currently pressed and if not, I'd like to continue with my program (like "INKEY$" in some BASIC-dialects). I tried several things: - event-handling from pygame: But that would open a pygame-window, I don't need. - same thing for window-managers like Tkinter. - threads: I couldn't do it (especially return values from thread-functions to the main-program). - curses: "nodelay()" or "halfdelay()" sound interesting. Maybe; but don't know how right now. I even wouldn't be able to "print" then ... - python-Xlib: Too complicated for me too right now; perhaps, if documentation becomes more complete. Does anybody know a code example (for Linux xterm) that does it ? TIA H. -- http://mail.python.org/mailman/listinfo/python-list
Re: Check for keypress on Linux xterm ?
Grant Edwards wrote: > On 2007-04-09, hlubenow <[EMAIL PROTECTED]> wrote: > >> My problem is, I don't want my program to wait for the keypress. >> I just want to check, if a key is currently pressed and if not, I'd like >> to continue with my program (like "INKEY$" in some BASIC-dialects). > > The answer to this frequently asked question is actually in the FAQ: > > http://www.python.org/doc/faq/library.html#how-do-i-get-a-single-keypress-at-a-time > > Google finds us further examples: > > http://mail.python.org/pipermail/pythonmac-sig/2004-February/010140.html > http://mail.python.org/pipermail/python-list/2000-June/041251.html You're answer is only less than half correct: Most of the given examples use something like c = sys.stdin.read(1) like my example does. This blocks input. At the end of your last link the author there says it. He also shows some ways into my direction. I'll test them. H. -- http://mail.python.org/mailman/listinfo/python-list
Re: Check for keypress on Linux xterm ?
Grant Edwards wrote: > On 2007-04-09, hlubenow <[EMAIL PROTECTED]> wrote: > >> My problem is, I don't want my program to wait for the keypress. >> I just want to check, if a key is currently pressed and if not, I'd like >> to continue with my program (like "INKEY$" in some BASIC-dialects). > > The answer to this frequently asked question is actually in the FAQ: > > http://www.python.org/doc/faq/library.html#how-do-i-get-a-single-keypress-at-a-time > > Google finds us further examples: > > http://mail.python.org/pipermail/pythonmac-sig/2004-February/010140.html > http://mail.python.org/pipermail/python-list/2000-June/041251.html > I see now, you're right. Sorry. -- http://mail.python.org/mailman/listinfo/python-list
Re: Check for keypress on Linux xterm ?
Grant Edwards wrote: > I do make mistakes, but before telling somebody he's wrong, it > might be a good idea to actually try what he's suggested. ;) I completely agree. The script waited at first for key-input, so I thought, I was right. But I was not. I apologize ! H. -- http://mail.python.org/mailman/listinfo/python-list
Re: Check for keypress on Linux xterm ?
I wrote:
> Hello,
>
> I'd like to check, if a single key is pressed on a Linux xterm.
> My problem is, I don't want my program to wait for the keypress.
> I just want to check, if a key is currently pressed and if not, I'd like
> to continue with my program (like "INKEY$" in some BASIC-dialects).
Ok, here's the code I use now. Thanks to Grant Edwards for pointing me into
the right direction:
--
#!/usr/bin/env python
import os
import sys
import tty
import termios
import fcntl
import time
fd = sys.stdin.fileno()
oldterm = termios.tcgetattr(fd)
oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
tty.setcbreak(sys.stdin.fileno())
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
def oldTerminalSettings():
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
def newTerminalSettings():
termios.tcsetattr(fd, termios.TCSANOW, newattr)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
def checkKey():
try:
c = sys.stdin.read(1)
return ord(c)
except IOError:
return 0
print
print "Ok, in 3 seconds, I'll check 100 times, which key you press."
print
# Initializing: Things like "raw_input()" won't work after that:
newTerminalSettings()
time.sleep(3)
for i in range(100):
a = "Key pressed: "
key = checkKey()
if key:
a += chr(key)
a += "."
else:
a += "Nothing pressed."
print a
# Somehow it doesn't work, if this loop runs too fast, so:
time.sleep(0.05)
oldTerminalSettings()
print
print "Terminal-settings restored."
print
raw_input("raw_input() works again. So please press Return: ")
print
--
Thanks again
H.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Stdout
[EMAIL PROTECTED] wrote:
> Dear Users,
>
> I am trying to recover through the python function
> popen3 the stdout,in,err of a launched process.
>
> I would like also to recover the stdout which you can
> get only through the command: command1 >& filename
>
> Do you know how I can access to that stdout by python?
>
> Thanks
>
> GIacomo
Check out module "subprocess" which is meant to replace function "popen3":
pr = subprocess.Popen(["command", "-option1", "-option2"], stdin =
subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE,
bufsize = 0, close_fds = True)
# And then:
line = pr.stdout.readline()
print line
pr.stdin.write("hello to command")
HTH
H.
--
http://mail.python.org/mailman/listinfo/python-list
