script files with python (instead of tcsh/bash)?

Esmail ebonak at
Wed Mar 25 13:34:18 CET 2009

Peter Otten wrote:
>> In this case I believe I needed the contents in a list because the line
>> I was looking for was above one that I could easily identify. Ie, once
>> I had the index, I could go back/up one index to find the line I needed
>> to process.
> Here's one way to avoid the list:
> last_line = None
> for line in f:
>     if "somestring" in line and last_line is not None:
>          # do something with last_line
>     last_line = line
> Peter

yup .. this will come in handy in case the file is too
big and or really needn't be all in memory. cool. thanks!


More information about the Python-list mailing list