extracting a set amount of lines from a Text file - Python
<p>let us imagine I have a text file with the following inside of it: (each line starts with a number and contains information next to it which I need) </p>

<blockquote>
  <p>1   325315</p>
  
  <p>2   234265</p>
  
  <p>3   345345</p>
  
  <p>4   234234</p>
  
  <p>5   373432</p>
  
  <p>6   436721 </p>
  
  <p>7   325262</p>
  
  <p>8   235268</p>
</blockquote>

<p>How would I go about extracting the lines that are after number 3 and before number 6 for example? While keeping the other data that is held on the same line.</p>

<p>I have a very large text file ~1000 lines, which I need to extract the lines starting with 300 through to 800. Either extract or remove the lines that I do not need, either way is ok.</p>

<p>Thanks for any help</p>

<p>Do like this.</p>

<pre><code>l = [line for line in (open('xyz.txt','r')).readlines() if int(line.split()[0]) &gt; 3 and int(line.split()[0]) &lt; 6 ]
</code></pre>

<p>Output:(Output will be lines between 3 and 6)</p>

<pre><code>C:\Users\dinesh_pundkar\Desktop&gt;python c.py
['4 234234\n', '5 373432\n']

C:\Users\dinesh_pundkar\Desktop&gt;
</code></pre>

python text