I have a text file with a lot of datetime strings in isoformat. The strings are similar to this:
'2009-02-10 16:06:52.598800'
These strings were generated using str(datetime_object)
. The problem is that, for some reason, str(datetime_object)
generates a different format when the datetime object has microseconds set to zero and some strings look like this:
'2009-02-10 16:06:52'
How can I parse these strings and convert them into a datetime object?
It's very important to get all the data in the object, including microseconds.
I have to use Python 2.5, I've found that the format directive %f
for microseconds doesn't exist in 2.5.