Actual Python 3 code, in case you're not convinced
import os
if os.isatty(1):
print("stdout is a tty")
else:
print("stdout is not a tty")
It really is that simple. Substitute the 1 for 0 when checking if stdin is a tty, and 2 if checking stderr