How do you open specific text files on python?
<p>I want to open specific lines from an ordinary text file in python. is there anyway to do this? and how?</p>

<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>

python