title: How to read and replace text in files in python line by line
body: <p>I am beginner in python and want to learn how to replace text from different files.</p>
  
  <p>I know how to do it basic, but need help with this:</p>
  
  <p>I have 3 files <em>main.txt</em>, <em>names.txt</em> and <em>number.txt</em></p>
  
  <p>names.txt looks like this:</p>
  
  <pre><code>Anna
  Smith
  Bob
  Jhon
  </code></pre>
  
  <p>number.txt looks like this:</p>
  
  <pre><code>1-522-223
  1-523-232
  1-593-573
  1-322-242
  </code></pre>
  
  <p>Line 1 in file names.txt corresponds with line 1 in number.txt (So anna's phone is the first one number.txt, Smith phone is 2nd in number.txt and so on)</p>
  
  <p>Now here is the problem:
  The file main.txt looks like this:</p>
  
  <pre><code>The person Judy lives in Ontario and has phone number 1-888-2923
  The person Michael lives in Toronto and has phone number 1-999-2388
  The person Cameron lives in Berlin and has phone number 1-666-2888
  The person Douglas lives in Tokyo and has phone number 5-7777-223
  </code></pre>
  
  <p>I know how to find and replace, the problem is I need to change the phone and name on each line in main.txt with the corresponding lines in <em>numbers.txt</em> and <em>names.txt</em>.
  So the edited <em>main.txt</em> should be:</p>
  
  <pre><code>The person Anna lives in Ontario and has phone number 1-522-223
  The person Smith lives in Toronto and has phone number 1-523-232
  The person Bob lives in Berlin and has phone number 1-593-573
  and so on...
  </code></pre>
  
  <p>I really have no clue how to do it, and the file is pretty big, like 2000 lines of text. Can anyone help me ?</p>