title: (Effectively) overwriting particular cell in .csv file using Python
body: <p>In pseudocode: I need a block of code that can access a .csv file, go to the <code>n</code>th row, with <code>n</code> being a predetermined random number between 1, 100, go to the 3rd column of nth row, and replace the <code>'FALSE'</code> string there with a string that reads <code>'TRUE'</code>. </p>
  
  <p>Here's what SO has told me so far: I might need to read the file, write over it to a new file, and then rename back to the original file name(?) for this to work. </p>
  
  <p>Here's the code I have thus far:</p>
  
  <pre><code>rnum = randint(1,100)
  file1 = open('file.csv', 'rb') 
  reader = csv.reader(file1)
  file2 = open('file11.csv', 'wb')
  writer = csv.writer(file2)
  for i, row in enumerate(reader):
      if i == rnum:
          row[2] = 'TRUE'
  writer.writerow(row)
  file1.close()
  file2.close()
  </code></pre>
  
  <p>The code doesn't work -- in the <code>file1.csv</code> file, all that is printed is the last row of the original .csv file, which isn't what I want. <br></p>
  
  <p>I suppose ideally the whole <code>file.csv</code> file should be transferred to the <code>file1.csv</code>, but with the <code>n</code>th row modified as described above. Thoughts? </p>
  
  <p>Sorry if this is an obvious question, I just started programming. </p>
  
  <p>Related SO questions on this topic: <br>
  <a href="https://stackoverflow.com/questions/11033590/change-specific-value-in-csv-file-via-python">Change specific value in CSV file via Python</a> <br>
  <a href="https://stackoverflow.com/questions/3699927/writing-to-a-particular-cell-using-csv-module-in-python">Writing to a particular cell using csv module in python</a> - this question suggests creating a function for this issue? <br>
  <a href="https://stackoverflow.com/questions/3146571/read-and-write-on-same-csv-file">read and write on same csv file</a></p>