Sometimes, it can be useful to know if your program is running in a terminal. Since Python 3.3, this functionality has been available in the
Here is an example of it in operation:
This is useful for many reasons. For example, scripts which have interactive “beautifications” like progress bars, no-freeze spinners, and animations should cease these antics when piped into the input of other programs or redirected to files. Additionally, programs being run from scripts can disable all performance-impacting interactivity, including interactive
KeyboardInterrupt handling; if a user
Ctrl+Cs a script, they want it to stop, immediately, not ask to quit.