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

Delaney, Timothy tdelaney at avaya.com
Wed May 29 22:09:43 EDT 2002


> From: Kragen Sitaker [mailto:kragen at pobox.com]
> 
> "Delaney, Timothy" <tdelaney at avaya.com> writes:
> > You should never rely on automatic freeing of *any* 
> resources unless it is
> > guaranteed. Always explicitly free resources when you have 
> finished with
> > them.
> 
> You mean, assume you have no garbage collector?  If I had to do that,
> my Python code would get a *lot* more complex.

Change that to "any resources not controlled by the system itself". Python
does not in fact guarantee a garbage collector, but does not provide any
mechanisms for freeing memory, so an implementation which did not free
memory would not be broken according to the documentation, but would be in
practice. Likewise, Python does not provide any mechanism for explicitly
allocating memory. Memory is controlled by the Python system.

OTOH, Python also makes no guarantees about finalisation, and this is of
course what I was referring to. Files are not a resource controlled by the
Python system. Python makes no guarantees that opened files will be closed.
Likewise sockets, spawned processes, etc.

Tim Delaney





More information about the Python-list mailing list