I m trying to do a some activity on class obj destruction. How do I achive file open in _del__ function? (I m using Python 3.4)
class iam(object):
def __in
Below is an alternate I used - Using atexit handlers:
import atexit
class iam(object):
def __init__(self):
print("I m born")
atexit.register(self.cleanup)
def cleanup(self):
f = open("memory_report.txt", "w")
f.write("He gone safe")
f.close()
print ("Done")
if __name__ == '__main__':
i = iam()
print("Script Ends. Now to GC clean memory")
I m born
Script Ends. Now to GC clean memory
Done