title: How to read a specific range of lines in an external file in python?
body: <p>Lets say you have a python file with 50 lines of code in it, and you want to read a specific range lines into a list. If you want to read ALL the lines in the file, you can just use the code from <a href="https://stackoverflow.com/questions/3277503/in-python-how-do-i-read-a-file-line-by-line-into-a-list#">this answer</a>:</p>
  
  <pre><code>with open('yourfile.py') as f:
      content = f.readlines()
  
  print(content)
  </code></pre>
  
  <p>But what if you want to read a specific range of lines, like reading line 23-27?</p>
  
  <p>I tried this, but it doesn't work:</p>
  
  <pre><code>f.readlines(23:27)
  </code></pre>