How to get the previous line in a file?

Mel Wilson mwilson at the-wire.com
Sun Mar 18 14:30:04 EDT 2007


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? 

Almost.  Strictly, we need to bind a name to the object holding the 
previous value, so we can refer to that object later.  :)




More information about the Python-list mailing list