Go to a specific line in Python?

Use Python Standard Library’s linecache module:

line = linecache.getline(thefilename, 33)

should do exactly what you want. You don’t even need to open the file — linecache does it all for you!

Leave a Comment