Re: Using xreadlines

2009-02-28 Thread Nick Craig-Wood
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

Re: Using xreadlines

2009-02-27 Thread Brett Hedges
: 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

Re: Using xreadlines

2009-02-27 Thread bearophileHUGS
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 --

Re: Using xreadlines

2009-02-27 Thread Roy H. Han
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

Re: Using xreadlines

2009-02-27 Thread Scott David Daniels
(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

Re: Using xreadlines

2009-02-27 Thread Roy H. Han
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,

Using xreadlines

2009-02-26 Thread Brett Hedges
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()

Re: Using xreadlines

2009-02-26 Thread Chris Rebert
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

Re: Using xreadlines

2009-02-26 Thread bearophileHUGS
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