Is there a way to maintain microsecond accuracy when converting a Python datetime to a timestamp?
>>> import datetime
>>> d1 = datetime.datetime(2013,7,31,9,13,8,829)
>>> import time
>>> d1_ts = time.mktime(d1.timetuple())
>>> d1
datetime.datetime(2013, 7, 31, 9, 13, 8, 829)
>>> d1_ts
1375279988.0
>>> d1.fromtimestamp(d1_ts)
datetime.datetime(2013, 7, 31, 9, 13, 8)
I lose that .829
on the conversion. This is rather important, because I have start and end timestamps that I need to step through at set intervals (with sub-second steps) to gather data from some sensors.
Eventually it will be used in a function similar to this:
from scipy import arange
sample_time = 0.02
for i in arange(d1_ts, d2_ts, sample_time):
# do stuff
With a sample_time
that small, the mircoseconds are important.