Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'elif': 0.05; 'output': 0.05; '#if': 0.07; 'sys': 0.07; 'assuming': 0.09; 'formatting': 0.09; 'friday,': 0.09; 'issue:': 0.09; 'lawrence': 0.09; 'none)': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'trailing': 0.09; 'try:': 0.09; 'python': 0.11; 'def': 0.12; 'language.': 0.14; 'posted': 0.15; '"%s"': 0.16; '#elif': 0.16; '.txt': 0.16; '1:09': 0.16; 'dict': 0.16; 'doesnt': 0.16; 'epoch': 0.16; 'imports': 0.16; 'key/value': 0.16; 'keys:': 0.16; 'logger': 0.16; 'pairs': 0.16; 'range.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'roy': 0.16; 'spacing': 0.16; 'storing': 0.16; 'strftime': 0.16; 'tab': 0.16; 'time.time()': 0.16; 'prevent': 0.16; 'language': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'subject:need': 0.19; 'thanks.': 0.20; '>>>': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'url:moin': 0.24; 'earlier': 0.24; 'post': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'point': 0.28; 'function': 0.29; 'program,': 0.31; 'code': 0.31; 'url:wiki': 0.31; '>>>>': 0.31; 'decimal': 0.31; 'doc': 0.31; 'file:': 0.31; 'keys': 0.31; 'pickle': 0.31; 'file': 0.32; 'thanks!': 0.32; 'run': 0.32; 'linux': 0.33; 'url:python': 0.33; 'ago': 0.33; 'guess': 0.33; 'maybe': 0.34; 'subject:the': 0.34; 'subject:from': 0.34; 'december': 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'but': 0.35; 'ubuntu': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'seconds': 0.37; 'unit': 0.37; 'list': 0.37; 'clear': 0.37; 'writes': 0.38; 'to:addr:python- list': 0.38; 'issue': 0.38; 'skip:- 10': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'how': 0.40; 'read': 0.60; 'above,': 0.60; 'commands': 0.60; 'number,': 0.60; 'new': 0.61; "you're": 0.61; 'email addr:gmail.com': 0.63; 'field': 0.63; 'our': 0.64; 'here': 0.66; 'date,': 0.68; 'of:': 0.68; 'prompt': 0.68; 'smith': 0.68; 'article': 0.77; 'batchelder': 0.84; 'copy-paste': 0.84; 'fragment': 0.84; 'received:89': 0.85; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: need to print seconds from the epoch including the millisecond Date: Mon, 30 Dec 2013 14:14:55 +0000 References: <59aa73ac-e06e-4c0e-83a4-147ac42cad2e@googlegroups.com> <0c33b7e4-edc9-4e1e-b919-fec210c92d4a@googlegroups.com> <1db0d993-9d2d-46af-9ee8-69d9250dc803@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-89-240-171-180.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 263 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1388412908 news.xs4all.nl 2969 [2001:888:2000:d::a6]:58485 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62885 On 30/12/2013 12:16, matt.doolittle33@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@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 > > 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