No file from stdin

Tartifola tartifola at gmail.com
Fri May 25 03:18:29 EDT 2007


Hi,


> On May 24, 9:48 am, Tartifola <tartif... at gmail.com> wrote:
> > Hi,
> > suppose a script of python is waiting for a file from the stdin and none
> > is given. How can I make the script to stop and, for example, print an
> > error message?
> >
> > Sorry for the n00b question and thanks
> 
> I'm not exactly sure what you mean. This assumes that you intended the
> contents of the file be piped in from the command line.
> [code]
> import sys
> 
> if sys.stdin.isatty():
>     print >>sys.stderr, "expected input from stdin"
>     sys.exit(1)

That's exactly what I was looking for. I did not know about isatty()
thanks



More information about the Python-list mailing list