title: Python csv : writing to a different directory
body: <p>I'm downloading files from a site and I need to save the original file, then open it and then add the url that the file was downloaded from and the date of the download to the file before saving the file to a different directory.</p>
  
  <p>I've used this answer to amend the csv: <a href="https://stackoverflow.com/questions/4872077/how-to-add-new-column-in-beginning-of-csv-file-by-python">how to Add New column in beginning of CSV file by Python</a></p>
  
  <p>but I'm struggling to redirect the file to a different directory before the write() function is called.</p>
  
  <p>Is the best answer to write the file and then move it, or is there a way to write the file to a different directory within the open() function?</p>
  
  <pre><code>if fileName in fileList:
      print "already got file "+ fileName
  else:
      # download the file
      urllib.urlretrieve(csvUrl, os.path.basename(fileName))
      #print "Saving to 1_Downloaded "+ fileName
  
      # open the file and then add the extra columns
      with open(fileName, 'rb') as inf, open("out_"+fileName, 'wb') as outf:
          csvreader = csv.DictReader(inf)
  
          # add column names to beginning
          fieldnames = ['url_source','downloaded_at'] + csvreader.fieldnames  
          csvwriter = csv.DictWriter(outf, fieldnames)
          csvwriter.writeheader()
          for node, row in enumerate(csvreader, 1):
              csvwriter.writerow(dict(row, url_source=csvUrl, downloaded_at=today))
  </code></pre>