Re: reading file in for loop

2014-09-05 Thread Peter Otten
loial wrote: > If I read a file using a for loop, as follows, is the file left open if I > execute a break in the for loop? > > > for line in open(myFile).readlines(): > > if something: > break Whether the file is left open has nothing to do with how you leave the loop. The way yo

Re: reading file in for loop

2014-09-05 Thread Chris Angelico
On Fri, Sep 5, 2014 at 8:20 PM, loial wrote: > If I read a file using a for loop, as follows, is the file left open if I > execute a break in the for loop? > > > for line in open(myFile).readlines(): > > if something: > break It'll be closed when the object expires. With CPython, tha

reading file in for loop

2014-09-05 Thread loial
If I read a file using a for loop, as follows, is the file left open if I execute a break in the for loop? for line in open(myFile).readlines(): if something: break -- https://mail.python.org/mailman/listinfo/python-list