Chosing between sys.argv and sys.stdin

Beat Bolli beat.bolli at earthling.net
Sat Oct 28 07:14:26 EDT 2000


> How would I add something that says "use sys.stdin if they don't include
> commandline arguments, but if neither is present, print the error
> message"? Right now, if it calls sys.stdin.read() and it wasn't piped
> into (like calling "spam.py" rather than "cat file | spam.py") it just
> sits there until I hit ctrl-d.

Look at isatty(), a method of any file object. It returns 1 if the file is connected
to a tty(-like) device, otherwise 0.

Beat Bolli
--
PGP: 0x506A903A; 49D5 794A EA77 F907 764F D89E 304B 93CF 506A 903A
ICBM: 47° 02' 43.0" N, 07° 16' 17.5" E (WGS84)





More information about the Python-list mailing list