Evaluating the next line in a For Loop while in the current iteration
<p>Here is what I am trying to do:
I am trying to solve an issue that has to do with wrapping in a text file. </p>

<p>I want to open a txt file, read a line and if the line contains what I want it to contain, check the next line to see if it does not contain what is in the first line. If it does not, add the line to the first line.</p>

<pre><code>    import re

    stuff = open("my file")

    for line in stuff:
        if re.search("From ", line):
            first = line
            print first
            if re.search('From ', handle.next()):
               continue
            else: first = first + handle.next()

        else: continue
</code></pre>

<p>I have looked a quite a few things and cannot seem to find an answer. Please help!</p>

<p>Thank you Martjin for helping me reset my mind frame! This is what I came up with:</p>

<pre><code>    handle = open("my file") 
    first = ""
    second = ""
    sent = ""
    for line in handle:
        line = line.rstrip()
        if len(first) &gt; 0: 
            if line.startswith("From "): 
                if len(sent) &gt; 0: 
                    print sent
                else: continue
                first = line
                second = ""
            else:
                second = second + line
        else:
            if line.startswith("From "): 
                first = line
        sent = first + second
</code></pre>

<p>It is probably crude, but it definitely got the job done!</p>

python python-2.7