python destroy object code example
Example 1: python delete object
class Thing(object):
def __del__(self):
print("Object was deleted.")
def func(self):
print("Random function ran from class Thing().")
random_object = Thing()
random_object.func()
del random_object
random_object.func()
Example 2: python delete class object
del <whatever object name you want to delete>
Example 3: python class destroying
class animal:
def __init__(self,name):
self.Name = name
def __del__(self):
print(self.Name+" has died D:")
ben = animal("Ben")
def deleteObj(obj):
del obj
deleteObj(ben)