bearophileh...@lycos.com bearophileh...@lycos.com wrote:
Brett Hedges:
My question is how do I go to a previous line in the file? xreadlines has a
file.next() statement that gives the next line, and I need a statement that
gives me the previous line.
In modern versions of Python you
: bearophileh...@lycos.com bearophileh...@lycos.com
Subject: Re: Using xreadlines
To: python-list@python.org
Date: Thursday, February 26, 2009, 8:09 PM
Brett Hedges:
My question is how do I go to a previous line in the
file? xreadlines has a file.next() statement that gives the
next line, and I
Brett Hedges:
How would I keep track of the absolute position of the lines?
You may have to do all things manually (tell, seek and looking for
newlines manually, iterating chars), that's why I have said it's not
handy. The other solutions are simpler.
Bye,
bearophile
--
Brett,
I'm not sure what exactly you're trying to do, but you can keep track
of line numbers using itertools.
import itertools
for lineIndex, line in itertools.izip(itertools.count(1), open('text.txt')):
print lineIndex, line
Here is sample code for breaking on a word and returning the
(1) Please do not top post in comp.lang.python, it violates conventions.
Brett Hedges (should have written):
bearophile wrote: ...
You can also keep track of the absolute position of the lines in the file, etc, or step
back looking for newlines, etc, but it's not handy
How would I keep
On Fri, Feb 27, 2009 at 12:20 PM, Scott David Daniels
scott.dani...@acm.org wrote:
(1) Please do not top post in comp.lang.python, it violates conventions.
Brett Hedges (should have written):
bearophile wrote: ...
You can also keep track of the absolute position of the lines in the
file,
Hi,
I am using both xreadlines and files iterators for a script that I need to
finish. I am iterating over the entire file but stopping to use xreadlines to
grab certain lines as strings to process them.
My question is how do I go to a previous line in the file? xreadlines has a
file.next()
On Thu, Feb 26, 2009 at 4:32 PM, Brett Hedges lilhedge...@yahoo.com wrote:
Hi,
I am using both xreadlines and files iterators for a script that I need to
finish. I am iterating over the entire file but stopping to use xreadlines to
grab certain lines as strings to process them.
My
Brett Hedges:
My question is how do I go to a previous line in the file? xreadlines has a
file.next() statement that gives the next line, and I need a statement that
gives me the previous line.
In modern versions of Python you usually don't need xreadlines,
because files are iterable.
If