title: how to find and replace in csv using python
body: <p>I have csv file with 900 rows and 11 columns. It contains approximately 4000 links which I want to replace with 4000 links (I have another csv file which contains both links in column 1 and 2). 
  I am trying to automate it (find and replace) using python 
  Here is my code but it is not working. Actually I am not getting any error but program run continuously without giving any results. I run it for 2. 3 hours and helplessly killed it. </p>
  
  <pre><code>import csv 
  def replace_all(text, dic):
    for i, j in dic.iteritems():
     text = text.replace(i, j)
   return text
  
  with open('file_that_find_replace_data.csv', mode='r') as infile:
   reader = csv.reader(infile)
   d = {rows[0]:rows[1] for rows in reader}
  
  f = open('main_file.csv','r') 
  filedata = f.read() 
  for row in filedata:
    newdata = replace_all(filedata, d)
  
  f = open('main_file.csv','w') 
  f.write(newdata) 
  f.close()
  print ('done')
  </code></pre>