all Python 3osfunction
os.isatty
os — terminals and devices
Check whether a file descriptor is attached to a terminal (tty).
Syntax
os.isatty(fd)
It lets a program behave differently in a terminal and under redirection: enable colour and progress bars only for a human, write plain text to a file. For a file object sys.stdout.isatty() does the same. On Windows the console counts as a terminal, a pipe does not.
Examples
import os
r, w = os.pipe()
print(os.isatty(r)) # → False
os.close(r)
os.close(w)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy