Re: How to get the previous line in a file?

2007-03-18 Thread Mel Wilson
Qilong Ren wrote: Hi, Shane, Thanks for fast reply. What I used is : for line in open(FILE): do stuff I don't want to store all lines in a list because sometimes the file is very large. We need to store the value of the previous line in a variable. Is that right?

How to get the previous line in a file?

2007-03-16 Thread Qilong Ren
Hi,all I am new to this list. And I am glade I am here. I have a question. I need to do some text processing. I need to read from a file line by line. If some line is met with some condition, the previous line needs some modification. How to get the info of the previous line? Thanks! Qilong

Re: How to get the previous line in a file?

2007-03-16 Thread Shane Geiger
lines = open('/tmp/foo.py', r).read().splitlines() previous_line = ''

Re: How to get the previous line in a file?

2007-03-16 Thread Qilong Ren
Hi, Shane, Thanks for fast reply. What I used is : for line in open(FILE): do stuff I don't want to store all lines in a list because sometimes the file is very large. We need to store the value of the previous line in a variable. Is that right? Thanks,Qilong -

Re: How to get the previous line in a file?

2007-03-16 Thread kyosohma
On Mar 16, 3:51 pm, Shane Geiger [EMAIL PROTECTED] wrote: lines = open('/tmp/foo.py', r).read().splitlines() previous_line = '' for line in lines: if foo in line: print found foo in the current line. The previous line is: + previous_line previous_line = line

Re: How to get the previous line in a file?

2007-03-16 Thread Paul McGuire
On Mar 16, 3:51 pm, Shane Geiger [EMAIL PROTECTED] wrote: lines = open('/tmp/foo.py', r).read().splitlines() previous_line = ''

Re: How to get the previous line in a file?

2007-03-16 Thread Jerry Hill
On 3/16/07, Qilong Ren [EMAIL PROTECTED] wrote: I have a question. I need to do some text processing. I need to read from a file line by line. If some line is met with some condition, the previous line needs some modification. How to get the info of the previous line? I would do something like

Re: How to get the previous line in a file?

2007-03-16 Thread dhn
On Mar 16, 5:10 pm, [EMAIL PROTECTED] wrote: On Mar 16, 3:51 pm, Shane Geiger [EMAIL PROTECTED] wrote: lines = open('/tmp/foo.py', r).read().splitlines() previous_line = '' for line in lines: if foo in line: print found foo in the current line. The previous