when should I explicitely close a file?

Ryan Kelly ryan at rfk.id.au
Tue Apr 13 23:10:25 EDT 2010


On Tue, 2010-04-13 at 18:19 -0700, Chris Rebert wrote:
> On Tue, Apr 13, 2010 at 5:45 PM, Giampaolo Rodola' <gnewsg at gmail.com> wrote:
> > What about open('foo', 'w').close().
> > Does it have the same problems?
> 
> Well, no, but that's only because it's a pointless no-op that doesn't
> really do anything besides possibly throwing an exception (e.g. if the
> script didn't have write access to the current directory).

Actually, it will create the file if it doesn't exist, and truncate it
to zero length if it does.


  Ryan


-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
ryan at rfk.id.au        |  http://www.rfk.id.au/ramblings/gpg/ for details





More information about the Python-list mailing list