title: How to read a whole file in Python? To work universally in command line
body: <p>How to read  a whole file in Python? I would like my script to work however it is called</p>
  
  <ul>
  <li><code>script.py log.txt</code></li>
  <li><code>script.py &lt; log2.txt</code></li>
  <li><code>python script.py &lt; log2.txt</code></li>
  <li><code>python -i script.py logs/yesterday.txt</code></li>
  </ul>
  
  <p>You get the idea.</p>
  
  <hr>
  
  <p>I tried</p>
  
  <pre><code>import fileinput
  from bs4 import BeautifulSoup
  f = fileinput.input()
  soup = BeautifulSoup(f.read())
  </code></pre>
  
  <p>But I get</p>
  
  <pre><code>Traceback (most recent call last):
    File "visual-studio-extension-load-times.py", line 5, in &lt;module&gt;
      soup = BeautifulSoup(f.read())
  AttributeError: FileInput instance has no attribute 'read'
  </code></pre>