I have a CLI script and want it to read data from a file. It should be able to read it in two ways :
cat data.txt | ./my_script.py
./my
You can use this function to detect if the input is from a pipeline or not.
sys.stdin.isatty()
It returns false if the input is from pipeline or true otherwise.