__del__ and AttributeError problem

Arun Sharma adsharma at home.com.nospam
Sat May 1 23:03:31 EDT 1999


I have 3 files:

$ cat foo.py
import bar
 
class foo:
 
        def __init__(self):
                self.i = 0
                self.j = bar.bar()
                bar.something()
 
        def __del__(self):
                print "foo dies\n"
                bar.something()
 
x = foo()           

$ cat bar.py
def something():
        print "bar something\n"
 
class bar:
 
        def __init__(self):
                self.i = 0
 
        def __del__(self):
                print "bar dies\n"
                                        
$ cat m.py
import bar
from foo import *    

$ python m.py
bar something
 
foo dies
 
Exception exceptions.AttributeError: "'None' object has no attribute 'something'" in <method foo.__del__ of foo instance at 80ad0c0> ignored
bar dies
           

Now for the question: why do I get the attribute error ? And what is
the right way to handle the situation ? I'm using python 1.5.1.

	-Arun




More information about the Python-list mailing list