Hi I am trying to make a Logfile for my class that anything happens to be written in there...
here is how my class looks like
class MyClass:
f = open('Log.txt','a')
def __init__(self):
self.f = open('Log.txt', 'a')
self.f.write("My Program Started at "+str(datetime.datetime.now())+"\n")
def __del__(self):
self.f.write("closing the log file and terminating...")
self.f.close()
my code works, but as you see above I have two f=open('Log.txt','a')
is there any way to avoid that ? I tried to delete one of them but it would yell at me... is there any better way to do this?
__init__s?it would yell at meis a vague way to describe a programming problem. Be precise. Please.