how can I run python interactively?

Q

questions?

I need to stop the program in the middle and pause there.

Are there anyway I can stop the program in the middle and have
something like:

please press y to continue.....

Thanks
 
G

graham.abbott

try something like ->

s = raw_input("Please Press a button...")
#s is the string they type.

Although i believe i remember a PEP that said they were removing
raw_input so perhaps

print "Please Press A button..."
s = sys.stdin.readline()

would be better, note the above requires you to 'import sys'
 
F

Fredrik Lundh

questions? said:
I need to stop the program in the middle and pause there.

Are there anyway I can stop the program in the middle and have
something like:

please press y to continue.....

portable:

raw_input("please press return to continue.....")

to get a single character, you can use msvcrt.getch() on windows,
or the termios module on unix:

http://effbot.org/librarybook/msvcrt.htm
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892
http://www.faqts.com/knowledge_base/view.phtml/aid/4490/fid/538
etc

</F>
 
G

Graham

You could use either:

s = raw_input("Please Hit a Key...")

s being the string they typed before hitting enter.

or you could use

print "Please hit a key..."
s = sys.stdin.readline()

the only reason i recommend the second is because i believe i saw in a
PEP that raw_input was being depreciated at some point, however i may
be wrong on that. (correction anyone?)
 
D

Dennis Lee Bieber

the only reason i recommend the second is because i believe i saw in a
PEP that raw_input was being depreciated at some point, however i may
be wrong on that. (correction anyone?)

If anything, I'd expect "input" to be the statement getting the
axe... After all, it's long been recommended to use raw_input instead of
input, and /then/ evaluate the data as needed.
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top