Determining if stdout for a Python process is redirected

Viewed 3786

I've noticed that curl can tell whether or not I'm redirecting its output (in which case it puts up a progress bar).

Is there a reasonable way to do this in a Python script? So:

$ python my_script.py
Not redirected

$ python my_script.py > output.txt
Redirected!

3 Answers
Related