does python have useless destructors?

Terry Reedy tjreedy at udel.edu
Fri Jun 11 11:31:16 EDT 2004


"Brian van den Broek" <bvande at po-box.mcgill.ca> wrote in message
news:40C9C2F2.1020201 at po-box.mcgill.ca...
> >>>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.

>   From that standpoint, I am wondering why the code that Michael P.
> Soulier provided above would worry an experienced Python programmer.

A reallybigbuffer might not fit on the hard disk, in which case writing
would raise an exception that it not caught.  For an application intended
to be run by thousands of users with disk of different capacities and
fullness and  who would be shocked to see a Python trackback appear (or
even worse, not see it before it disappears), this would be bad.

As the next poster says, 'depends on the circumstances'.  If you are
writing private code to run on your own machine with gigabytes of free
space, hardy worth worrying about.

> I've read the rest of the thread, but the ensuing references to C++ RAII

With 30yrs experience, I have no idea what this is either.  It must be
something new in C++ since I ceased paying attention some years ago after
settling on Python for my needs.

> malloc,

short for 'memory allocate', the C function that does just that.  Without
knowing that, yes, it could be parsed as 'mal locatation' or 'mall
occasion' or whatever ;-)

Terry J. Reedy







More information about the Python-list mailing list