Skip to content
File Methods

isatty()

Return True if the file stream is interactive (connected to a terminal device).

file.isatty()

file.isatty() returns True if the file stream is connected to a TTY-like interactive terminal device.

Returns

True if connected to a terminal; otherwise False.

Try it

Run it and change it
import tempfile
with tempfile.NamedTemporaryFile(mode='w+', delete=True) as f:
    print('Is disk file TTY:', f.isatty())

Worth knowing

  • Color & interactive output: CLI applications often check sys.stdout.isatty() before printing ANSI color codes or interactive spinners.

Related entries