title: how to write back to open csv file in python
body: <p>I'm trying to go through a csv file, validate zip codes and write the city and state to the last column in the csv file. </p>
  
  <p>I managed to get the csv data and get the city and state, but I don't understand how to write the new data to the last column.  SO examples like <a href="https://stackoverflow.com/questions/9372705/how-to-write-a-list-to-a-csv-file">this</a> show how to create a csv, but not work with an existing csv.</p>
  
  <p>here is my code so far:</p>
  
  <pre><code>with open("propertyOutput.csv", "rbw") as fp:
      reader = csv.DictReader(fp, skipinitialspace=True)
      table = [row for row in reader]
      for rows in table:
          stringNeed = rows['zip']
          if not stringNeed.isdigit(): 
              print"not number"  #would like to write this to the column
              pass
          else:
              if not len(stringNeed) == 5:  
                  print"string not 5 long"  # would like to write this to the column
              else:
                  x = getCityState(stringNeed)
                  print x  # would like to write this to the column
  </code></pre>