I want a program to do one thing if executed like this:
cat something | my_program.py
and do another thing if run like this
my_program.py
But if I read from stdin, then it will wait for user input, so I want to see if there is anything to read before trying to read from stdin.
If you want to detect if someone is piping data into your program, or running it interactively you can use isatty to see if stdin is a terminal: