title: Iteration not working in 'with open' of CSV module in Python
body: <p>I want to create 2 or more CSV files using <code>for</code> but only 1 CSV is created.</p>
  
  <pre><code>import csv
  import os
  
  foods = ['pasta','chocolate']
  for food in foods:
      with open(food+'.csv', 'w') as csvfile:
          fieldnames = ['id', 'Category', 'Name']
  
          writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
          writer.writeheader()
          os.chdir('E:/data/'+food)
          folders = os.listdir(os.curdir)
          for filename in folders:
                  writer.writerow({'id':'', 'Category':food, 'Name':filename})
  </code></pre>
  
  <p>In this case, only <code>pasta.csv</code> is successfully created. I want the <code>chocolate.csv</code> also created.
  Any solutions? Thanks</p>