with open('com1', 'r') as f:

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Apr 4 14:09:51 EDT 2009


En Sat, 04 Apr 2009 11:29:22 -0300, gert <gert.cuykens at gmail.com> escribió:

> On Apr 4, 12:58 am, Lawrence D'Oliveiro <l... at geek-
> central.gen.new_zealand> wrote:
>> In message <8bc55c05-19da-41c4-
>>
>> b916-48e0a4be4... at p11g2000yqe.googlegroups.com>, gert wrote:
>> >     with open('com1', 'r') as f:
>> >         for line in f:
>> >              print('line')
>>
>> Why bother, why not just
>>
>>     for line in open('com1', 'r') :
>>         print line
>
> Interesting :)
> So its does the same thing as with right ?
> Automatic closing and finalizing stuff.

No, it does not. Either use `with` o a `try...finally` block.

-- 
Gabriel Genellina




More information about the Python-list mailing list