title: Quickly opening and closing csv?
body: <p>I'm working on a program in python that converts a csvs to a list of lists. It does this multiple times for different files so I made it into a function. I haven't encountered errors with this, but I'm worried it's the most pythonic/smartest/fastest way, because these are enormous csvs. </p>
  
  <pre><code>import csv
  
  searchZipCode = #there's a zip code here
  zipCoords = #there's a file here
  
  def parseFile(selected):
      with open(selected) as selectedFile:
              selectedReader = csv.reader(selectedFile, delimiter=',')
              for row in selectedReader:
                      yield row
  
  def parseZips():
      return parseFile(zipCoords)
  
  zips = parseZips()
  for row in zips:
      if row[0] == searchZipCode:
              searchState = row[1]
              searchLat   = row[2]
              searchLong  = row[3]
              print searchState 
  </code></pre>
  
  <p>Basically, I'm wondering why <code>for row</code> has to repeat twice. Is there not a more elegant solution?</p>