PDA

View Full Version : Python std::in???



djbushido
January 16th, 2009, 09:59 PM
How would one go about getting input from std::in on python?
My idea is to get something like the C++ equivalent of cin.get(), such that it grabs only 1 character. This is probably a stupid question, but I can't find it documented anywhere.
Thanks!

days_of_ruin
January 16th, 2009, 10:30 PM
string = raw_input("enter a character:")
print string

Wybiral
January 16th, 2009, 11:28 PM
import sys
print sys.stdin.read(1)

djbushido
January 16th, 2009, 11:37 PM
thanks for the sys.stdin, that should work! will let you know if it doesn't.

eightmillion
January 17th, 2009, 12:05 AM
$ echo "The quick brown fox jumped over the lazy dog." | python -c 'import sys;print sys.stdin.read()'
The quick brown fox jumped over the lazy dog.