Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'interpreter': 0.05; 'url:pipermail': 0.05; 'float': 0.07; 'string': 0.09; 'friday,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'themselves,': 0.09; 'truncated': 0.09; 'python': 0.11; 'thread': 0.14; '2.7.2': 0.16; '2.7.3': 0.16; 'guessing': 0.16; 'luckily,': 0.16; 'precision,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'repr()': 0.16; 'reproduce': 0.16; 'simpson': 0.16; 'str()': 0.16; 'time.time()': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'subject:need': 0.19; 'feb': 0.22; '>>>': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'received:comcast.net': 0.24; 'decide': 0.24; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'points': 0.29; 'statement': 0.30; "i'm": 0.30; 'asked': 0.31; '>>>>': 0.31; 'decimal': 0.31; 'sep': 0.31; 'time;': 0.31; 'thanks!': 0.32; 'url:python': 0.33; 'running': 0.33; 'ago': 0.33; 'maybe': 0.34; 'subject:the': 0.34; 'subject:from': 0.34; 'december': 0.35; 'something': 0.35; 'objects': 0.35; 'right?': 0.36; 'ubuntu': 0.36; 'similar': 0.36; 'url:org': 0.36; 'two': 0.37; 'to:addr :python-list': 0.38; 'issue': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'url:mail': 0.40; 'how': 0.40; 'days': 0.60; "you're": 0.61; 'you.': 0.62; 'email addr:gmail.com': 0.63; 'show': 0.63; 'places': 0.64; 'more': 0.64; 'different': 0.65; 'feeling': 0.68; 'confusing': 0.84; '2013,': 0.91; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: need to print seconds from the epoch including the millisecond Date: Mon, 30 Dec 2013 07:50:40 -0500 References: <0c33b7e4-edc9-4e1e-b919-fec210c92d4a@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: c-50-133-228-126.hsd1.ma.comcast.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; 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: 84 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1388407860 news.xs4all.nl 2864 [2001:888:2000:d::a6]:42534 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62881 On 12/29/13 9:44 PM, matt.doolittle33@gmail.com wrote: > On Friday, December 27, 2013 7:25:42 PM UTC-5, Cameron Simpson wrote: >> On 27Dec2013 07:40, 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! >> >> >> >> Repeatedly people have asked you to show your exact code. Still nothing. >> >> >> >> Here's a clue, from a Gentoo box running kernel 3.2.1-gentoo-r2: >> >> >> >> $ python >> >> Python 2.7.2 (default, Feb 9 2012, 18:40:46) >> >> [GCC 4.5.3] on linux2 >> >> Type "help", "copyright", "credits" or "license" for more information. >> >> >>> import time; print time.time() >> >> 1388190100.44 >> >> >>> import time; time.time() >> >> 1388190102.795531 >> >> >>> >> >> >> >> Please show us _exactly_ what you're doing. I'm guessing that print >> >> is confusing you. >> >> >> > matt@matt-Inspiron-1525:~$ python > Python 2.7.3 (default, Sep 26 2013, 16:38:10) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import time; print time.time() > 1388371148.39 >>>> import time; time.time() > 1388371173.556624 >>>> > > i get the same result as you expect. so its got to be the write statement that is truncated the decimal places right? > Objects in Python have two different ways to produce a string of themselves, known as the str() and the repr(). A float's str() includes two decimal points of precision, its repr() includes as many as you'd need to reproduce the float again. The print statement implicitly uses the str(), the interactive interpreter uses the repr(). Luckily, you can decide how to format the float yourself: >>> import time >>> time.time() 1388407706.617985 >>> print time.time() 1388407709.21 >>> print "%.3f" % time.time() 1388407716.377 >>> print "%.4f" % time.time() 1388407726.1001 BTW, I said something very similar in this thread 2.5 days ago: https://mail.python.org/pipermail/python-list/2013-December/663454.html I get the feeling not all messages are flowing to all places. -- Ned Batchelder, http://nedbatchelder.com