title: cant close last opened file
body: <p>Hello if i have following code:</p>
  
  <pre><code>n = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])
  for i in range(0, n):
      dat_file = r'C1/C10000' + str(i).zfill(2) + '.dat'
      csv_file = r'C1_conv/C10000' + str(i).zfill(2) + '.csv'
      in_dat = csv.reader(open(dat_file, 'rb'), delimiter = '\t')
      out_csv = csv.writer(open(csv_file, 'wb'))
      out_csv.writerows(in_dat)
  </code></pre>
  
  <p>The problem i have is, that the last file stays opened.
  I tried to close it with in_dat.close()...., but have read that its not possible because it is a parser.</p>
  
  <p>I have read about the 'with' function, but don't know how to put this in.
  Could someone show me the proper code, please?</p>
  
  <p>Thanks :D</p>