program in interactive mode

B.G.R. nospam at
Sun Dec 26 21:55:14 CET 2004

"Alex Martelli" <aleaxit at> escribió en el mensaje
news:1gpf7qp.c9e4w97cdazzN%aleaxit at
> B.G.R. <nospam at> wrote:
>    ...
> > numline=0
> > for line in sys.stdin:
> >     numline+=1
> >     workwithline(line)
> Consider the alternative:
>     for numline, line in enumerate(sys.stdin):
> Nothing to do with your main program, but still neater...
> > that's ok, but if the user only does "./" then I got to get
> > interactive mode and show a prompt in every line expecting the user
> > for that line. Problem is I don't know how to tell if I've been "piped"
> sys.stdin.isatty() should serve you well.
> Alex

Thank you all very much for your help and tips, that's exactly what I was
looking for.
I guess my knowledge of the libraries is still quite limited. Time to work
on that too.


More information about the Python-list mailing list