In a module I defined a class with the following __init__ method:
class RMLoader(object):
def __init__(self):
self.now=datetime.datetime.now()
then I’m importing that module in console:
>>> from video.remmedia.loader import RMLoader
>>> loader=RMLoader()
>>> loader.now
datetime.datetime(2010, 11, 4, 17, 40, 36, 523000)
the question is why it not gives me standard datetime object?
but when i do print it act like standard datetime object:
>>> print loader.now
2010-11-04 17:40:36.523000
But I steel cant use it in function where i need datetime object…
How can I use that attribute like standard datetime?
It is a standard
datetimeobject all the time. The difference is thatloader.nowwill invokerepr, andprint loader.nowwill invokestr. The first one is designed to give an accurate representation of the object, ideally one that would evaluate to an identical object. The second one is designed to provide a readable representation of the object.There is documentation on this here.