title: How can I resolve this I/O Error in when trying to save a file in python?
body: <p>I am getting the following error with this code: <em>line 8, in 
  for line in csv_reader:
  ValueError: I/O operation on closed file</em></p>
  <pre><code>import csv
  import re
  
  with open('file.csv', 'r') as csv_file:
      csv_reader = csv.reader(csv_file)
  
  ff = []
  for line in csv_reader:
         ff.append([re.search('mfgcode=&quot;(.+?)&quot;', line[0] ).group(1),re.search('modelno=&quot;(.+?)&quot;', line[0] ).group(1),re.search('qtyavail=&quot;(.+?)&quot;', line[0] ).group(1)])
          
  df = pd.DataFrame(ff,columns =['mfgcode','modelno','qtyavail'])
  df.to_csv(&quot;test.csv&quot;,index=False)
  print (df)
  </code></pre>
  <p>What could be the error preventing this from saving a file?</p>