heres a dumb question....
Jason Orendorff
jason at jorendorff.com
Mon Feb 4 20:43:31 EST 2002
Jeremy Bush writes:
> [...] cant seem to figure out how to get keyboard input...
> ive read the whole readme that came with it, the tutorial,
> everything.
raw_input() gets a line of input.
Unlike C++, you ordinarily get a line at a time, and split it
to get the information you want.
For example, if you expect the user to type in numbers
separated by commas, you'd do:
line = raw_input('> ') # see? you can provide a prompt
fields = line.split(',')
for s in fields:
x = float(s) # convert string to float
print "you entered the number:", x
If you "import sys", then you have sys.stdin, which is a file object.
File objects have various methods for input. Viz:
http://www.python.org/doc/current/lib/bltin-file-objects.html
Enjoy Python!
## Jason Orendorff http://www.jorendorff.com/
More information about the Python-list
mailing list