use fileinput to read a specific line

Martin Marcher martin at
Tue Jan 8 11:04:33 CET 2008

jo3c wrote:

> i need to read line 4 from a header file

~/2delete $ cat data.txt

~/2delete $ python
Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import linecache
>>> linecache.getline("data.txt", 2)
>>> linecache.getline("data.txt", 5)
>>> linecache.getline("data.txt", 1)


You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

More information about the Python-list mailing list