[Tutor] (no subject)
Daniel Yoo
dyoo@hkn.eecs.berkeley.edu
Tue, 28 Nov 2000 04:17:56 -0800 (PST)
On Mon, 27 Nov 2000, Devansh Dhutia wrote:
> i was wondering if its possible in python to be able to read the keystrokes
> from a keyboard??
> for example, if a user was to input a sequence of numbers or letters, i want
> to be able to display them elsewhere on the screen immediately after the
> user presses a key.
Hello! You can do rudimentary input with the functions:
raw_input()
input()
Here's a sample interpreter session that shows how to use raw_input():
###
>>> def queryAndGreet():
... name = raw_input("Please enter your name here: ")
... print "Hello", name, "nice to meet you."
...
>>> queryAndGreet()
Please enter your name here: Devansh
Hello Devansh nice to meet you.
###
You'll probably want to use raw_input() to read in your strings; input()
has a more specialized purpose.
However, I get the feeling that your question asked for more control over
screen input and output. If you want fine-tuned control over what happens
on the screen, you might want to look at the curses library:
http://python.org/doc/current/lib/module-curses.html
The curses library will let you position characters at any coordinate of
your text screen. You might need to learn a little more Python before
using it, but you'll definitely have some fun with it.
http://www.python.org/doc/howto/curses/curses.html
Finally, I wrote some hideously ugly code that works with the curses
library, if you want an example. Take a look here:
http://hkn.eecs.berkeley.edu/~dyoo/python/circularwriting.py