Problems with select() and stdin

jepler at unpythonic.net jepler at unpythonic.net
Sun Aug 18 11:34:20 EDT 2002


When you take input from a pipe, sys.stdin corresponds to the program on
the left of the pipeline, not the terminal where the program is running (if
any).

If you open the special device /dev/tty and assign the result to sys.stdin,
raw_input reads from the terminal again, as in this example:

$ echo "standard input" | python -c '
import sys;
print sys.stdin.read(),;
sys.stdin = open("/dev/tty");
print raw_input("? ")'
standard input
? _

This advice only applies to unix where /dev/tty is supported.

Jeff




More information about the Python-list mailing list