 <p>If the lines are selected by line numbers which follow a consistent pattern, use <a href="https://docs.python.org/3.6/library/itertools.html#itertools.islice" rel="nofollow"><code>itertools.islice</code></a>.</p> <p>E.g. To select every second line from line 3 up to but not including line 10:</p> <pre><code>import itertools with open('my_file.txt') as f: for line in itertools.islice(f, 3, 10, 2): print(line) </code></pre>