if STREAM.isatty():

Eryk Sun eryksun at gmail.com
Thu Aug 29 10:16:12 EDT 2019


On 8/29/19, Rhodri James <rhodri at kynesim.co.uk> wrote:
>
> "isatty()" is a method of the io.IOBase class that checks to see
> if the stream is connected to a tty, or to use less jargon, if it is
> interactive.  "tty" was I think originally an abbreviation for
> "teletype", but nowadays it refers to any terminal, anywhere you
> get a command line prompt.

In Windows, isatty() is true for any character-type file. This does
not necessarily mean an interactive stream. In particular, NUL is a
character device:

    C:\>python -c "import  sys;print(sys.stderr.isatty())" 2>NUL
    True

But a pipe is not:

    C:\>python -c "import  sys;print(sys.stderr.isatty())" 2>&1 | more
    False



More information about the Python-list mailing list