How to detect if a pipe is attached to stdout
This can be detected using isatty
.
import sys
if sys.stdout.isatty():
# You're running in a real terminal
else:
# You're being piped or redirected
Example and solution from StackOverflow.
This can be detected using isatty
.
import sys
if sys.stdout.isatty():
# You're running in a real terminal
else:
# You're being piped or redirected
Example and solution from StackOverflow.