title: Pythonic way to keep track of line number in stdin
body: <p>I am writing a python script that takes input from stdin and would like to keep track of the line number of the input from stdin. </p>
  
  <p>I could create a counter myself, but I have a feeling that python automatically keeps track of the line number, and thus it would be a waste of computation. I have not found how to get/print that number though.</p>
  
  <p>I have read about and tried the .tell() method, but it tracks characters (or bytes) and not lines. Also it seems to fail when input is from stdin. It throws <code>IOError: [Errno 29] Illegal seek</code></p>
  
  <p>My test script "pythonTest.py" looks like:</p>
  
  <pre><code>import sys
  with sys.stdin as file:
      for line in file:
          print(line.rstrip())
          # Neat way to print the line number
  </code></pre>
  
  <p>Upon executing the one above (as it is now):</p>
  
  <pre><code>$ echo 'asdf
  asdf
  asdf
  asdf' | python pythonTest.py
  adsf
  asdf
  asdf
  asdf
  </code></pre>
  
  <p>I want:</p>
  
  <pre><code>$ echo 'asdf
  asdf
  asdf
  asdf' | python pythonTest.py
  adsf
  1
  asdf
  2
  asdf
  3
  asdf
  4
  </code></pre>
  
  <p>Is there a nice and pythonic way to do this, or is the standard solution to just add your own counter to the for-loop?</p>