No need to close file?

T ty.2006 at yahoo.com
Tue Jul 18 17:04:12 EDT 2006


Thomas Bartkus wrote:
> "T" <ty.2006 at yahoo.com> wrote in message
> news:1153252214.457508.269880 at 35g2000cwc.googlegroups.com...
> > Do I need to close the file in this case?  Why or why not?
> >
> > for line in file('foo', 'r'):
> >   print line
>
> Are you asking if you can get away without closing it?
> Or are you asking if it is a good idea to not close it?
>
> Good programming practice says that if you open it - you close it.
>
> And stay out of trouble ;-)
> Thomas Bartkus



How do I close the file in the above case?




More information about the Python-list mailing list