python: grab a specific line after a match
<p>I have have df full of text<br>
I would like to define variable <strong>date</strong> which is always three lines after <strong>version</strong>.
here is my code</p>

<pre><code>with open(input_file1,'r') as f:
    for i, line in enumerate(f):
        if line.startswith('Version'):
            version = line.strip()
            date = line + 3
            print(line,date)
</code></pre>

<p>but it does not work for the <strong>date</strong> variable and i receive the following error. Can anybody help?</p>

<pre><code>TypeError: Can't convert 'int' object to str implicitly
</code></pre>

<p><code>line</code> is the string contents of the line in the file. <code>i</code> is the incrementally increasing index of the line being parsed. Therefore you want to read line number <code>i+3</code>. You can read three lines ahead easily if you read all the lines into memory with <code>.readlines()</code>.<br>
<strong>NOTE</strong> this is not advisable if your files are very large!</p>

<pre><code>with open(input_file1,'r') as f:
    lines = f.readlines()
    for i, line in enumerate(lines):
        if line.startswith('Version'):
            version = line.strip()
            date = lines[i + 3].strip()
            print(line,date)
</code></pre>

python loops lines