Class destructor -- strange behaviour

Spes Vlastimil.Holer at gmail.com
Thu Dec 6 16:51:08 EST 2007


Hi,

I have this simple code:
| #!/usr/bin/python
| import codecs
| import re
| from copy import deepcopy
|
| class MyClass(object):
|   def __del__(self):
|     deepcopy(1)
|
| x=MyClass()

but I get an error:
| Exception exceptions.TypeError: "'NoneType' object is not callable"
in <bound method MyClass.__del__ of <__main__.MyClass object at
0x6fcf0>> ignored

The problem disappears if I do anything of this:
1. change
     - from copy import deepcopy
     + import copy
    and call directly copy.deepcopy(1)

or
2. don't store object to variable `x'

or
3. don't import module `re'

The first solution is OK, but I would like to know why it behaves so
strange. We have tested on:

- Mac OS X Tiger for PPC
Python 2.3.5 (#1, Mar 20 2005, 20:38:20)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin

- Linux 64bit and 32bit
Python 2.4.4 (#1, Oct 30 2007, 14:31:50)
[GCC 4.1.2 (Gentoo 4.1.2 p1.0.2)] on linux2
Python 2.5 (r25:51908, Jan 12 2007, 13:57:15)
[GCC 4.0.2 20051125 (Red Hat 4.0.2-8)] on linux2

Thanks for the explanation,
Vlasta



More information about the Python-list mailing list