How to get millisec/fractional seconds out of a time object ?
M.-A. Lemburg
mal at egenix.com
Wed Jan 7 14:10:58 EST 2009
On 2009-01-06 22:34, David at bag.python.org wrote:
> Thanks for help to a beginner.
>
> script23
> import time
> import datetime
> start_time = datetime.datetime.now()
> time.sleep(0.14)
> end_time = datetime.datetime.now()
> datetime.timedelta = end_time - start_time
> print(datetime.timedelta) # works, prints 0:00:0.141000
> print(datetime.timedelta.seconds) # prints 0
> print(datetime.timedelta.milliseconds) # fails
> < object has no attribute milliseconds >
>
> How do I get the 0.141000 out of that or any time object ?
> On line docs are arcane to a novice.
If you're only interested in the fractional seconds part, you're
much better off with doing:
import time
start_time = time.time()
...
end_time = time.time()
delta_seconds = end_time - start_time
delta_milliseconds = delta_seconds * 1000
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Jan 07 2009)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-list
mailing list