title: Python replace value in text file
body: <p>I'm trying to replace a value in a specific line in a text file.</p>
  
  <p>My text file contains count of the searchterm, searchterm &amp; date and time</p>
  
  <p>Text file:</p>
  
  <pre><code>MemTotal,5,2016-07-30 12:02:33,781
  model name,3,2016-07-30 13:37:59,074
  model,3,2016-07-30 15:39:59,075
  </code></pre>
  
  <p>How can I replace for example the count of the searchterm for line 2 (<code>model name,3,2016-07-30 13:37:59,074</code>)?</p>
  
  <p>This is what I have already:</p>
  
  <pre><code>f = open('file.log','r')
  filedata = f.read()
  f.close()
  
  newdata = filedata.replace("2", "3")
  
  f = open('file.log', 'w')
  f.write(newdata)
  f.close()
  </code></pre>
  
  <p>It replace all values <code>2</code>.</p>