Skip to content
Advertisement

How to read a whole file in Python? To work universally in command line

How to read a whole file in Python? I would like my script to work however it is called

  • script.py log.txt
  • script.py < log2.txt
  • python script.py < log2.txt
  • python -i script.py logs/yesterday.txt

You get the idea.


I tried

JavaScript

But I get

JavaScript

Advertisement

Answer

Instead of using fileinput, open the file directly yourself:

JavaScript
Advertisement