It is microsecond
, without an "s" at the end
'datetime.datetime' object has no attribute 'microseconds'
-
25-06-2022 - |
Frage
I am writing a script in python and I need to know how many milliseconds are between two points in my code.
I have a global variable when the program starts like this:
from datetime import datetime
a=datetime.now()
When I need to know how many milliseconds have passed, I execute this:
b=datetime.now()
print (b.microseconds-a.microseconds)*1000
However I get this error:
AttributeError: 'datetime.datetime' object has no attribute 'microseconds'
What's wrong? How can I fix this?
Lösung
Andere Tipps
A useful function is dir
. You can do dir(object)
to find out its properties. In this case, you want a.microsecond
.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow