Is there a way in Python 3 to check whether the following command
print('Hello')
prints to the terminal by using
python3 example.py
or prints to the file by using
python3 example.py > log.txt
...? In particular, is there a way to print different things depending on whether I use > log.txt
or not?