Sep-02-2024, 05:31 PM
Hi to all, i've got a question that i hope someone can help with, i've bought a book with examples and one of those examples used a destructor method, which was ok.
#Define a destructor method, which is called when all object resources are deleted class MyClass: def __init__(self): print("Constructor is called") def __del__(self): print("Destructor is called") print("Object deleted") obj = MyClass() del objwhat i tried to do was to add the name of the object being deleted to the print output, just to show what was getting deleted, but seem to have ran into a brick wall with what i thought would work, here's what i thought would work, could someone tell me please if this is possible, all responses are appreciated.
#Define a destructor method, which is called when all object resources are deleted class MyClass: def __init__(self): print("Constructor is called") def __del__(self,obname): print("Destructor is called") print("Object deleted" + self.obname) obj = MyClass() nameit = "obj" del obj,nameit