title: How to Populate List of Starting Positions of Each Line Using For-loop and Tell Function?
body: <p>All I want to do is create a list of the starting positions of each line so I can seek to them really fast. I am getting the error, "telling position disabled by 'next()' call." How do I overcome this?</p>
  
  <pre><code>&gt;&gt;&gt; in_file = open("data_10000.txt")
  &gt;&gt;&gt; in_file.tell()
  0
  &gt;&gt;&gt; line_numbers = [in_file.tell() for line in in_file]
  Traceback (most recent call last):
    File "&lt;pyshell#9&gt;", line 1, in &lt;module&gt;
      line_numbers = [in_file.tell() for line in in_file]
    File "&lt;pyshell#9&gt;", line 1, in &lt;listcomp&gt;
      line_numbers = [in_file.tell() for line in in_file]
  OSError: telling position disabled by next() call
  </code></pre>
  
  <p>Note: in this context, the index would relate the line number to the seek position.</p>