A file iteration question/problem

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Apr 7 09:44:37 EDT 2008


En Mon, 07 Apr 2008 10:09:13 -0300, <tinnews at isbd.co.uk> escribió:
> Arnaud Delobelle <arnodel at googlemail.com> wrote:

>> def recfun(lines):
>>     for line in lines:
>>         # Do stuff
>>         if condition:
>>             recfun(lines)
>>
>> lines = iter(open(filename))
>> recfun(lines)
>>
> Does that work though?  If you iterate through the file with the "for
> line in lines:" in the first call of recfun(lines) you surely can't do
> "for line in lines:" and get any sort of sensible result in recursive
> calls of recfun(lines) can you?

Why not? Test and see what happens.

-- 
Gabriel Genellina




More information about the Python-list mailing list