annoying stdin/stdout + pipes problem

Damjan gdamjan at gmail.com
Sun Sep 23 12:24:04 EDT 2007


> I want to create a program that reads input from stdio that can prompt
> a user for input while doing so without getting into problems.
...
> As you can see I have commented out what I'd like to do but do not
> know how to. Can I somehow halt the previous print to stdout (cat
> input.txt) - if so can I then start it again, and how?

The trick (which works on Linux for sure) is to open /dev/tty and ask
question/get input on/from it.

fp = open('/dev/tty', 'r+')
fp.write('Prompt: ')
answer = fp.readline().strip()


I'm not usre for other *nix-es, and on Windows this will surelly not work
-- 
damjan



More information about the Python-list mailing list