[Tutor] interactif or not

Alan G alan.gauld at freenet.co.uk
Tue Jun 7 23:15:57 CEST 2005


> > look to see if stdin is a tty. Unix is usually very careful about
who has a
> > "controlling tty" and who does not. In Python, file objects have
an isatty()
> > method that will return True or False.
> >
> > import sys
> > isinteractive = sys.stdin.isatty()
> > if isinteractive:
> > ...
> > else:
> > ...
> >
>
> tested and it works !

Aha! I knew about tty on Unix so I looked in the os module for it,
I never thought of it being a file method....

Alan G.



More information about the Tutor mailing list