How do you check whether stdout is a terminal, and why would you?
IntermediateConceptOS, filesystem, subprocess & CLIs
Answer
sys.stdout.isatty() is True for an interactive terminal and False when piped or redirected (CI logs, | jq, > file). Use it to disable colors and progress bars, emit JSON by default in pipelines, and refuse interactive prompts. sys.stdin.isatty() tells you if you can prompt the user at all.
More on OS, filesystem, subprocess & CLIs
`os.path` vs `pathlib`: which do you use and why?BeginnerHow do you read environment variables safely?BeginnerHow do you walk a directory tree and find files?BeginnerWhat does `shutil` give you that `os` does not?BeginnerHow do you run an external command correctly with `subprocess`?BeginnerWhy is `shell=True` dangerous, and when is it acceptable?Intermediate