Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62819
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Subject | Re: need to print seconds from the epoch including the millisecond |
| Date | 2013-12-27 13:49 -0500 |
| References | (4 earlier) <l9ijl4$e2c$1@ger.gmane.org> <mailman.4650.1388120007.18130.python-list@python.org> <0c33b7e4-edc9-4e1e-b919-fec210c92d4a@googlegroups.com> <roy-CC46A3.11275827122013@news.panix.com> <1db0d993-9d2d-46af-9ee8-69d9250dc803@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4676.1388170207.18130.python-list@python.org> (permalink) |
On 12/27/13 1:09 PM, matt.doolittle33@gmail.com wrote:
> On Friday, December 27, 2013 11:27:58 AM UTC-5, Roy Smith wrote:
>> In article <0c33b7e4-edc9-4e1e-b919-fec210c92d4a@googlegroups.com>,
>>
>> matt.doolittle33@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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
need to print seconds from the epoch including the millisecond matt.doolittle33@gmail.com - 2013-12-26 10:32 -0800
Re: need to print seconds from the epoch including the millisecond Dan Stromberg <drsalists@gmail.com> - 2013-12-26 11:22 -0800
Re: need to print seconds from the epoch including the millisecond matt.doolittle33@gmail.com - 2013-12-26 14:06 -0800
Re: need to print seconds from the epoch including the millisecond Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-27 09:34 +1100
Re: need to print seconds from the epoch including the millisecond Grant Edwards <invalid@invalid.invalid> - 2014-01-02 16:23 +0000
Re: need to print seconds from the epoch including the millisecond Dave Angel <davea@davea.name> - 2014-01-02 21:41 -0500
Re: need to print seconds from the epoch including the millisecond Grant Edwards <invalid@invalid.invalid> - 2014-01-03 15:33 +0000
Re: need to print seconds from the epoch including the millisecond Chris Angelico <rosuav@gmail.com> - 2014-01-04 02:41 +1100
Re: need to print seconds from the epoch including the millisecond Dave Angel <davea@davea.name> - 2013-12-26 17:48 -0500
Re: need to print seconds from the epoch including the millisecond Terry Reedy <tjreedy@udel.edu> - 2013-12-26 20:03 -0500
Re: need to print seconds from the epoch including the millisecond Roy Smith <roy@panix.com> - 2013-12-26 20:29 -0500
Re: need to print seconds from the epoch including the millisecond matt.doolittle33@gmail.com - 2013-12-27 07:43 -0800
Re: need to print seconds from the epoch including the millisecond Dave Angel <davea@davea.name> - 2013-12-26 23:54 -0500
Re: need to print seconds from the epoch including the millisecond matt.doolittle33@gmail.com - 2013-12-27 07:42 -0800
Re: need to print seconds from the epoch including the millisecond matt.doolittle33@gmail.com - 2013-12-27 07:40 -0800
Re: need to print seconds from the epoch including the millisecond Dave Angel <davea@davea.name> - 2013-12-27 11:20 -0500
Re: need to print seconds from the epoch including the millisecond Roy Smith <roy@panix.com> - 2013-12-27 11:27 -0500
Re: need to print seconds from the epoch including the millisecond matt.doolittle33@gmail.com - 2013-12-27 10:09 -0800
Re: need to print seconds from the epoch including the millisecond Roy Smith <roy@panix.com> - 2013-12-27 13:50 -0500
Re: need to print seconds from the epoch including the millisecond Roy Smith <roy@panix.com> - 2013-12-27 13:53 -0500
Re: need to print seconds from the epoch including the millisecond Roy Smith <roy@panix.com> - 2013-12-27 20:15 -0500
Re: need to print seconds from the epoch including the millisecond Ned Batchelder <ned@nedbatchelder.com> - 2013-12-27 13:49 -0500
Re: need to print seconds from the epoch including the millisecond matt.doolittle33@gmail.com - 2013-12-30 04:16 -0800
Re: need to print seconds from the epoch including the millisecond Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-30 14:14 +0000
Re: need to print seconds from the epoch including the millisecond Cousin Stanley <cousinstanley@gmail.com> - 2013-12-30 10:07 -0700
Re: need to print seconds from the epoch including the millisecond Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-30 17:35 +0000
Re: need to print seconds from the epoch including the millisecond Cousin Stanley <cousinstanley@gmail.com> - 2013-12-30 11:17 -0700
Re: need to print seconds from the epoch including the millisecond Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-31 05:57 +1100
Re: need to print seconds from the epoch including the millisecond Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-27 13:14 -0500
Re: need to print seconds from the epoch including the millisecond Cameron Simpson <cs@zip.com.au> - 2013-12-28 11:25 +1100
Re: need to print seconds from the epoch including the millisecond matt.doolittle33@gmail.com - 2013-12-29 18:44 -0800
Re: need to print seconds from the epoch including the millisecond Ned Batchelder <ned@nedbatchelder.com> - 2013-12-30 07:50 -0500
Re: need to print seconds from the epoch including the millisecond Roy Smith <roy@panix.com> - 2013-12-30 09:22 -0500
Re: need to print seconds from the epoch including the millisecond Ned Batchelder <ned@nedbatchelder.com> - 2013-12-30 08:01 -0500
Re: need to print seconds from the epoch including the millisecond matt.doolittle33@gmail.com - 2013-12-30 05:40 -0800
Re: need to print seconds from the epoch including the millisecond Ned Batchelder <ned@nedbatchelder.com> - 2013-12-27 21:10 -0500
Re: need to print seconds from the epoch including the millisecond Steven D'Aprano <steve@pearwood.info> - 2013-12-28 03:50 +0000
csiph-web