title: Don't understand Python's csv.reader object
body: <p>I've come across a behavior in python's built-in csv module that I've never noticed before. Typically, when I read in a csv, it's following the <a href="https://docs.python.org/2/library/csv.html" rel="noreferrer">doc's</a> pretty much verbatim, using 'with' to open the file then looping over the reader object with a 'for' loop. However, I recently tried iterating over the csv.reader object twice in a row, only to find out that the second 'for' loop did nothing.</p>
  
  <pre><code>import csv
  
  with open('smallfriends.csv','rU') as csvfile:
  readit = csv.reader(csvfile,delimiter=',')
  
  for line in readit:
      print line
  
  for line in readit:
      print 'foo'
  </code></pre>
  
  <p>Console Output:</p>
  
  <pre><code>Austins-iMac:Desktop austin$ python -i amy.py 
  ['Amy', 'James', 'Nathan', 'Sara', 'Kayley', 'Alexis']
  ['James', 'Nathan', 'Tristan', 'Miles', 'Amy', 'Dave']
  ['Nathan', 'Amy', 'James', 'Tristan', 'Will', 'Zoey']
  ['Kayley', 'Amy', 'Alexis', 'Mikey', 'Sara', 'Baxter']
  &gt;&gt;&gt;
  &gt;&gt;&gt; readit
  &lt;_csv.reader object at 0x1023fa3d0&gt;
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>So the second 'for' loop basically does nothing. One thought I had is the csv.reader object is being released from memory after being read once. This isn't the case though since it still retains it's memory address. I found a <a href="https://stackoverflow.com/questions/4856172/python-csv-reader-isnt-reading-csv-data-the-way-i-expect">post</a> that mentions a similar problem. The reason they gave is that once the object is read, the pointer stay's at the end of the memory address ready to write data to the object. Is this correct? Could someone go into greater detail as to what is going on here? Is there a way to push the pointer back to the beginning of the memory address to reread it? I know it's bad coding practices to do that but I'm mainly just curious and wanting to learn more about what goes on under Python's hood.</p>
  
  <p>Thanks!</p>