Does python hate cathy?

Terry Reedy tjreedy at udel.edu
Mon Mar 24 04:03:55 EDT 2008


"QS" <qingshan.chen at gmail.com> wrote in message 
news:a5e95efc-f8cd-4595-bbbd-f5f59c45ea89 at u72g2000hsf.googlegroups.com...

>From the title, I assumed this was spam like others with similar titles --
and that the perl newsgroup, for instance, would have 'Does perl hate 
cathy?

| I am new to python, and I encountered a weird problem.

Observation: as you will learn, the form of the error message was different 
from the standard tracebacks one gets during program execution.  This was a 
clue that it was a cleanup message and actually did make sense.

Summary lessons.

1. What a Python interpreter does after it executes the last statement is 
undefined by the language spec.  It could do absolutely nothing (and I wish 
some programs that wastefully spend minutes 'cleaning up' did just that!). 
CPython tries to do some cleanup when requested but the results are 
sometimes seemingly arbitrary.

2. If you use __del__, do so for a reason (and keeping a population count 
is one, though rare*), and explicitly delete the objects for which you want 
dependable behavior.

*A population count is a good example of a class attribute.  But it seems 
to be rare in practice because if one wants that, it seems that a 
population collection (with a len() method) is usually also wanted --  
perhaps so one can iterate thru the population.

3. Experimenting with Python is a good way to learn.  Keep it up!

tjr






More information about the Python-list mailing list