469,356 Members | 1,994 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

eric3 question

Hello All!

I'am using eric3 IDE under win32 (snapshot 2005-04-10), and have a trouble. I
use this code:
print "enter q to quit, or smthing else to continue"
while not sys.stdin.readline()=="q":
smthing(else)

I can't run this code to debug in eric3. The questions are - how to fix it and
how to ask user for press a key without troubles with eric?

msvcrt.kbhit don't work also.

Thank you in advance

Alexander, za**@bk.ru
Jul 19 '05 #1
5 1310
Alexander Zatvornitskiy wrote:
Hello All!

I'am using eric3 IDE under win32 (snapshot 2005-04-10), and have a trouble. I
use this code:
print "enter q to quit, or smthing else to continue"
while not sys.stdin.readline()=="q":
smthing(else)


Try using raw_input() instead of the sys.stdin.readline(). raw_input()
is the preferred way of getting console input.

Like this:
print "enter q to quit, or smthing else to continue"
while not raw_input() == 'q':
smthing(else)

Or you can do it this way:
while not raw_input("enter q to quit, or smthing else to continue: ")
smthing(else)

Gerrit van Dyk
Jul 19 '05 #2
Le Tue, 31 May 2005 03:13:31 +0400, Alexander Zatvornitskiy a Иcrit :
Hello All!

I'am using eric3 IDE under win32 (snapshot 2005-04-10), and have a trouble. I
use this code:
print "enter q to quit, or smthing else to continue"
while not sys.stdin.readline()=="q":
smthing(else)
prompt = "enter q to quit, or smthing else to continue"
req = raw_input(prompt)
if req == "q":
raise SystemExit()
smthing(else) Thank you in advance

Alexander, za**@bk.ru

Jul 19 '05 #3
Gerrit van Dyk wrote:
Try using raw_input() instead of the sys.stdin.readline(). raw_input()
is the preferred way of getting console input.
Is it? Guido's "Python Regrets" slides (Google for them) seems
to say the opposite. Besides, that's not the problem here...

Alexander Zatvornitskiy wrote: I'am using eric3 IDE under win32 (snapshot 2005-04-10), and have a trouble. I use this code:
print "enter q to quit, or smthing else to continue"
while not sys.stdin.readline()=="q":
smthing(else)


That will actually work in a vanilla Unix Python interpreter
if you type q followed by Ctrl-D twice, but I suspect that's
not what you intended...

The readline method includes the whole line, including the
linefeed character if you press q followed by ENTER. If you
change it to...

while not sys.stdin.readline()=="q\n":

....I guess it will work in eric3. (It works in IDLE then.)
You might even want something more robust, such as

while not sys.stdin.readline().strip().lower() == "q":

In general, your construct makes it a bit difficult for you
to debug your own code. If you had written it like below...

while True:
inp = sys.stdin.readline()
if inp == 'q':
break
smthing(else) # Not that you can use else as a name...

....it would have been trivial to insert "print repr(inp)"
which ought to have given you a clue of what was going on...

Changes and experiments like that are very easy to do in
Python. It beats staring at the code in confusion 99 times
out of 100. It's typically much faster than asking on c.l.py,
although not educational for as many people... ;)
Jul 19 '05 #4
Привет Magnus!

31 мая 2005 в 13:46, Magnus Lycka в своем письме к All писал:
ML> The readline method includes the whole line, including the
ML> linefeed character if you press q followed by ENTER. If you
ML> change it to...

ML> while not sys.stdin.readline()=="q\n":
oooops. I'am usually use Ctrl+C to break my program, so this bug was not found
by me.
ML> ...I guess it will work in eric3. (It works in IDLE then.)
no. under eric3, exception "The socket operation could not completed without
blocking" on line 160 in AsincFile.py (this file is from python's
distribution). It seems, cause of bug is in method of redirection the console
input/output to eric's windows.

Btw, raw_input works fine.

ML> In general, your construct makes it a bit difficult for you
ML> to debug your own code. If you had written it like below...

ML> while True:
ML> inp = sys.stdin.readline()
ML> if inp == 'q':
ML> break
ML> smthing(else) # Not that you can use else as a name...
I hate such loops. Usually, if I see the loop, I want to see its condition at
once, I don't want to search for it. In my opinion, "while True"+"break" is
something like "goto"+"if" or even worse.
ML> Changes and experiments like that are very easy to do in
ML> Python. It beats staring at the code in confusion 99 times
ML> out of 100. It's typically much faster than asking on c.l.py,
ML> although not educational for as many people... ;)
Anyway, now you know that eric3 use (possibly) little bit buggy mechanism for
redirection of input/output. It's cool:)

Alexander, za**@bk.ru
Jul 19 '05 #5
Привет F.!

31 мая 2005 в 06:08, F. Petitjean в своем письме к All писал:
I'am using eric3 IDE under win32 (snapshot 2005-04-10), and have a
trouble. I use this code: print "enter q to quit, or smthing else
to continue" while not sys.stdin.readline()=="q":
smthing(else)

FP> prompt = "enter q to quit, or smthing else to continue"
FP> req = raw_input(prompt)
FP> if req == "q":
FP> raise SystemExit()
FP> smthing(else)
Thank you, raw_input works fine in eric3.

Alexander, za**@bk.ru
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Geoffrey Clements | last post: by
4 posts views Thread by reh | last post: by
3 posts views Thread by Lupe | last post: by
reply views Thread by Surya Kiran | last post: by
4 posts views Thread by Reiner Block | last post: by
22 posts views Thread by dataangel | last post: by
2 posts views Thread by Arso - Italy | last post: by
reply views Thread by Julius Lucks | last post: by
2 posts views Thread by Byte | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.