does python have useless destructors?

Brian van den Broek bvande at po-box.mcgill.ca
Fri Jun 11 10:34:26 EDT 2004


Aahz said unto the world upon 10/06/2004 16:56:

> In article <-oadnfu_sdwTUFrdRVn-hw at powergate.ca>,
> Peter Hansen  <peter at engcorp.com> wrote:
> 
>>Michael P. Soulier wrote:
>>
>>>myfile = open("myfilepath", "w")
>>>myfile.write(reallybigbuffer)
>>>myfile.close()
>>
>>... immediately raises a warning flag in the mind of an
>>experienced Python programmer.
> 
> 
> Depends on the circumstance, I'd think.


Hi all,

I'm still learning Python as a first language since some BASIC quite some 
time ago, so my level of knowledge/understanding is not too sophisticated. 
  From that standpoint, I am wondering why the code that Michael P. 
Soulier provided above would worry an experienced Python programmer.

I've read the rest of the thread, but the ensuing references to C++ RAII, 
malloc, etc. are not yet within my grasp. (I recognize I'm not really the 
target audience of the thread.) I'd google for an explanation, but I don't 
have a clear sense of what to google for.

I had thought I was being careful and smart by always checking for 
filepath existence and always explicitly closing files, but I am wondering 
what red flag I'm overlooking.

Any pointers for stuff to read to understand the comment would be appreciated.

Thanks and best to all,

Brian vdB





More information about the Python-list mailing list