title: how to merge two files line by line using python
body: <p>input:      </p>
  
  <pre><code> hai how are you
   a      
   b
  </code></pre>
  
  <p>input2: </p>
  
  <pre><code>   1
     hello 
     2
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>hai how areyou
  1
  a
  hello
  b
  2
  </code></pre>
  
  <p>I tried with this code </p>
  
  <pre><code>with open('file_1', 'rt') as file1, \
   open('file_2') 'rt' as file2, \
   open('merged_file', 'wt') as outf:
  
  for line in heapq.merge(file1, file2):
      outf.write(line)
  </code></pre>
  
  <p>but i didn't get expected results</p>
  
  <p>how can i achieve this using python give me hint</p>