I'm defining a class that has a time attribute which, but default, is set as the current UTC time.
import datetime
class Timer:
def __init__(self, time = datetime.datetime.utcnow()):
self.time = time
print('Instance created at', self.time)
a = Timer()
The problem is that once defined (or when it is imported, if it's within module), this attribute is set forever! All new instances of the class "inherit" the time from the class, evaluated when it was defined, instead of generating its own "current time" when __init__
is called. Why isn't the function to obtaint current UTC time evaluated every time a new instance is created?