1class Thing(object):
2 # The function below runs when this object is deleted.
3 # I just put it there so you can visulise it properly.
4 def __del__(self):
5 print("Object was deleted.")
6
7 def func(self):
8 print("Random function ran from class Thing().")
9
10random_object = Thing()
11random_object.func() # Run the function so you know the class exists.
12del random_object # Delete the object. Will run the __del__ function when done this.
13
14# Try to run the func() function now, it won't run because the object is deleted.
15random_object.func() # Produces NameError.
1>>> class Test:
2... def __del__(self):
3... print "deleted"
4...
5>>> test = Test()
6>>> del test
7deleted