title: Multiple lines into single line in Python
body: <p>I have a file as follows:</p>
  
  <pre><code>&gt;abc
  AAA
  AAA
  &gt;dfgg
  BBBBB
  BBBBB
  BB
  &gt;zzz
  CCCCC
  CCC
  </code></pre>
  
  <p>My desired output is:</p>
  
  <pre><code>&gt;abc
  AAAAAA
  &gt;dfgg
  BBBBBBBBBBBB
  &gt;zzz
  CCCCCCCC
  </code></pre>
  
  <p>That is turning multiple lines into a single line.</p>
  
  <p>I wrote the following code:</p>
  
  <pre><code>f = open('test.txt', 'r')
  currentline = ""
  for line in f:
      if line.startswith('&gt;'):
          line = line.rstrip('\n')
          print line
      else:
          line = line.rstrip('\n')
          currentline = currentline + line
          print currentline
  f.close()
  </code></pre>
  
  <p>Of course, this is not right as the <code>currentline</code> keeps on growing until the end. I can't figure out how I can update the <code>currentline</code> and print the output as indicated. </p>
  
  <p>I know one option is to read the whole file either with <code>f.read()</code> or <code>f.readlines()</code> and treat the file as string or list but as the file is very large and each line that doesn't start with '>' can go up to 20 million characters, I thought it's better not to read the whole file into memory at once and treat it line by line. Please let me know what you think of that.</p>
  
  <p>Thanks for any help!</p>