Why no open(f, "w").write()?

John La Rooy larooy at xtar.co.nz
Sat Jun 1 03:25:11 EDT 2002


On 1 Jun 2002 01:23:42 GMT
"Michael P. Soulier" <msoulier at nortelnetworks.com_.nospam> wrote:

> On Fri, 31 May 2002 22:55:04 +1200, John La Rooy <larooy at xtar.co.nz> wrote:
> > 
> > Do you explicitly del all your objects too, or wait for them to disappear
> > when they go out of scope?
> 
>     I only delete them in C++. ;-) Your point is taken, but we must draw the
> line somewhere. If you don't care when the file is closed, as long as it is,
> then implicit should be fine. If however you do care when it is closed, then
> explicit should be better, no?
> 
>     Mike

I've often used the 'open(f, "w").write()' right at the end of a program where
I know the file is about to get closed anyway. From what I've seen here about
Jython, it seems that I can't even count on that behaviour. eeek!

Perhaps the specification will some day change to make the objects returned by
open() to be *smarter* so we can count on them knowing when they should flush
and when they should close the toilet seat.

A few people seem to be getting stuck on the explicit instead of implicit idea
but I think that is mostly because we are used to be told to close files
and we've all had a few late nights because we forgot to. Just as lots of us
learned we should always free() our mallocs() and now we think nothing of
letting python do that housekeeping for us.

cloudcuckoo-land-ly y'rs - John



More information about the Python-list mailing list