osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

if STREAM.isatty():


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