need to print seconds from the epoch including the millisecond
Mark Lawrence
breamoreboy at yahoo.co.uk
Mon Dec 30 09:14:55 EST 2013
On 30/12/2013 12:16, matt.doolittle33 at gmail.com wrote:
> On Friday, December 27, 2013 1:49:54 PM UTC-5, Ned Batchelder wrote:
>> On 12/27/13 1:09 PM, matt.doolittle33 at gmail.com wrote:
>>
>>> On Friday, December 27, 2013 11:27:58 AM UTC-5, Roy Smith wrote:
>>
>>>> In article <0c33b7e4-edc9-4e1e-b919-fec210c92d4a at googlegroups.com>,
>>
>>>>
>>
>>>> matt.doolittle33 at gmail.com wrote:
>>
>>>>
>>
>>>>
>>
>>>>
>>
>>>>> I am on Ubuntu 12.10. I am still working with the 2 decimal places.
>>
>>>>
>>
>>>>> Sometime ago i had this issue and I forget how i solved it. maybe i used
>>
>>>>
>>
>>>>> datetime? thanks!
>>
>>>>
>>
>>>>
>>
>>>>
>>
>>>> That's strange. Linux should give you time to the microsecond, or
>>
>>>>
>>
>>>> something in that range.
>>
>>>>
>>
>>>>
>>
>>>>
>>
>>>> Please post the *exact* code you're running. The code you posted
>>
>>>>
>>
>>>> earlier is obviously only a fragment of some larger program, so we can
>>
>>>>
>>
>>>> only guess what's happening. Assuming your program is in a file called
>>
>>>>
>>
>>>> "prog.py", run the following commands and copy-paste the output:
>>
>>>>
>>
>>>>
>>
>>> i cant run it that way. i tried using the python prompt in terminal but got nothing. but here is all the code relevant to this issue:
>>
>>> #all the imports
>>
>>> import sys
>>
>>> import posixpath
>>
>>> import time
>>
>>> from time import strftime
>>
>>> from datetime import datetime
>>
>>> import os
>>
>>> import wx
>>
>>> import cPickle as pickle
>>
>>> import gnuradio.gr.gr_threading as _threading
>>
>>>
>>
>>>
>>
>>> #the function that writes the time values
>>
>>> def update(self, field_values):
>>
>>>
>>
>>> now = datetime.now()
>>
>>>
>>
>>> #logger ---------------
>>
>>> # new line to write on
>>
>>> self.logfile.write('\n')
>>
>>> # write date, time, and seconds from the epoch
>>
>>> self.logfile.write('%s\t'%(strftime("%Y-%m-%d",)))
>>
>>> self.logfile.write('%s\t'%(now.strftime("%H:%M:%S",)))
>>
>>> self.logfile.write('%s\t'%(time.time()))
>>
>>> # list to store dictionary keys in tis order
>>
>>> keys = ["duid", "nac", "tgid", "source", "algid", "kid"]
>>
>>> # loop through the keys in the right order
>>
>>> for k in keys:
>>
>>> # get the value of the current key
>>
>>> f = field_values.get(k, None)
>>
>>> # if data unit has value...
>>
>>> if f:
>>
>>> # output the value with trailing tab
>>
>>> self.logfile.write('%s\t'%(str(f)))
>>
>>> # if data unit doesnt have this value print a tab
>>
>>> else:
>>
>>> self.logfile.write('\t')
>>
>>> #end logger ----------------
>>
>>>
>>
>>> #if the field 'duid' == 'hdu', then clear fields
>>
>>> if field_values['duid'] == 'hdu':
>>
>>> self.clear()
>>
>>> elif field_values['duid'] == 'ldu1':
>>
>>> self.clear()
>>
>>> elif field_values['duid'] == 'ldu2':
>>
>>> self.clear()
>>
>>> #elif field_values['duid'] == 'tdu':
>>
>>> # self.clear()
>>
>>> #loop through all TextCtrl fields storing the key/value pairs in k, v
>>
>>> for k,v in self.fields.items():
>>
>>> # get the dict value for this TextCtrl
>>
>>> f = field_values.get(k, None)
>>
>>> # if the value is empty then set the new value
>>
>>> if f:
>>
>>> v.SetValue(f)
>>
>>>
>>
>>> #sample output in a .txt file:
>>
>>>
>>
>>> 2013-12-27 12:07:33 1388164053.18
>>
>>> 2013-12-27 12:07:33 1388164053.36
>>
>>> 2013-12-27 12:07:33 1388164053.54
>>
>>> 2013-12-27 12:07:33 1388164053.73
>>
>>> 2013-12-27 12:07:33 1388164053.91
>>
>>> 2013-12-27 12:07:34 1388164054.11
>>
>>> 2013-12-27 12:07:34 1388164054.28
>>
>>> 2013-12-27 12:07:34 1388164054.48
>>
>>> 2013-12-27 12:07:34 1388164054.66
>>
>>> 2013-12-27 12:07:34 1388164054.84
>>
>>> 2013-12-27 12:07:37 1388164057.62
>>
>>> 2013-12-27 12:07:37 1388164057.81
>>
>>> 2013-12-27 12:07:37 1388164057.99
>>
>>> 2013-12-27 12:07:38 1388164058.18
>>
>>> 2013-12-27 12:07:38 1388164058.37
>>
>>> 2013-12-27 12:07:38 1388164058.54
>>
>>> 2013-12-27 12:07:38 1388164058.73
>>
>>> 2013-12-27 12:07:38 1388164058.92
>>
>>>
>>
>>> Thanks!
>>
>>>
>>
>>
>>
>> Instead of:
>>
>>
>>
>> "%s" % time.time()
>>
>>
>>
>> try:
>>
>>
>>
>> "%.6f" % time.time()
>>
>>
>>
>> %.6f is a formatting code meaning, floating-point number, 6 decimal places.
>>
>>
>>
>> --
>>
>> Ned Batchelder, http://nedbatchelder.com
>
> thanks a bunch. the "%.6f" was the cure. can you please point me to the doc for formatting time? Thanks!
>
Would you please read and action this
https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the
double line spacing above, thanks.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Python-list
mailing list