Cannot find what I'm sure is a simple command... please help
Sean 'Shaleh' Perry
shalehperry at attbi.com
Sun Mar 31 18:33:04 EST 2002
More information about the Python-list mailing list
Sun Mar 31 18:33:04 EST 2002
- Previous message (by thread): Cannot find what I'm sure is a simple command... please help.
- Next message (by thread): Cannot find what I'm sure is a simple command... please help.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 31-Mar-2002 A. Jones wrote: > I seem to have either overlooked, or completely missed a function that > allows one to open a specific line of a file. > > I've read through my Learning Python book, and read the relevent > module docs (anything having to do with files, and the __builtins__). > I must have overlooked such a function. > > I thought the seek() function might work, but it only seems to give me > a byte offset in the file, and not a line number. > there is no way to do this with the libraries shipped with python. An obvious implementation is: def get_desired_line(filename, desired_line): fp = open(filename) lines = fp.readlines() return lines[desired_line - 1]
- Previous message (by thread): Cannot find what I'm sure is a simple command... please help.
- Next message (by thread): Cannot find what I'm sure is a simple command... please help.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list