Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62748 > unrolled thread

need to print seconds from the epoch including the millisecond

Started bymatt.doolittle33@gmail.com
First post2013-12-26 10:32 -0800
Last post2013-12-28 03:50 +0000
Articles 17 on this page of 37 — 14 participants

Back to article view | Back to comp.lang.python


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#62830

FromRoy Smith <roy@panix.com>
Date2013-12-27 20:15 -0500
Message-ID<roy-3058E3.20153327122013@news.panix.com>
In reply to#62818
matt.doolittle33@gmail.com wrote:
> I need to print the time in seconds from the epoch with 
> millisecond precision.  

I wrote:

> What happens if you do:
> 
> t = time.time()
> self.logfile.write("str=%s, repr=%s", (str(t), repr(t)))

At the time I originally posted that, I was baffled as to what was going 
on and was simply feeding you suggestions for how to go about debugging 
the problem logically.

However, I have since figured out exactly what's going on.  I'm going to 
do you a favor and NOT tell you what I've figured out (because you won't 
learn anything that way), but I will give you a hint.  The hint is that 
if you run the two lines of code I suggested above, the answer should be 
obvious.

And, once you do that, please report your findings back to us, because 
it's a fun little quirk of Python and one that I suspect has tripped up 
more than a few people over time.  In fact, I seem to recall being 
mystified by this myself once.

[toc] | [prev] | [next] | [standalone]


#62819

FromNed Batchelder <ned@nedbatchelder.com>
Date2013-12-27 13:49 -0500
Message-ID<mailman.4676.1388170207.18130.python-list@python.org>
In reply to#62816
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

[toc] | [prev] | [next] | [standalone]


#62880

Frommatt.doolittle33@gmail.com
Date2013-12-30 04:16 -0800
Message-ID<bfb11374-f074-418a-9531-d2af614985bc@googlegroups.com>
In reply to#62819
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!

[toc] | [prev] | [next] | [standalone]


#62885

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-12-30 14:14 +0000
Message-ID<mailman.4716.1388412908.18130.python-list@python.org>
In reply to#62880
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

[toc] | [prev] | [next] | [standalone]


#62889

FromCousin Stanley <cousinstanley@gmail.com>
Date2013-12-30 10:07 -0700
Message-ID<l9s982$mdd$1@dont-email.me>
In reply to#62885
>> On 30/12/2013 12:16, matt.doolittle33@gmail.com wrote:
>> ....
>>
>> 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.

  You might consider either turning off an option
  in your news client for including message in reply
  and/or snipping all but a few lines for context
  to prevent us from seeing the double line spacing
  all over again .... :-)
 

-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

[toc] | [prev] | [next] | [standalone]


#62890

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-12-30 17:35 +0000
Message-ID<mailman.4721.1388424933.18130.python-list@python.org>
In reply to#62889
On 30/12/2013 17:07, Cousin Stanley wrote:
>
>>> On 30/12/2013 12:16, matt.doolittle33@gmail.com wrote:
>>> ....
>>>
>>> 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.
>
>    You might consider either turning off an option
>    in your news client for including message in reply
>    and/or snipping all but a few lines for context
>    to prevent us from seeing the double line spacing
>    all over again .... :-)
>

Great idea, but one slight snag is the poster then doesn't see how many 
newlines they've managed to insert using their superb tool.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#62892

FromCousin Stanley <cousinstanley@gmail.com>
Date2013-12-30 11:17 -0700
Message-ID<l9sdck$in9$1@dont-email.me>
In reply to#62890
>> You might consider either turning off an option
>> in your news client for including message in reply
>> and/or snipping all but a few lines for context
>> to prevent us from seeing the double line spacing
>> all over again .... :-)
 
> Great idea, but one slight snag is 
> the poster then doesn't see how many newlines 
> they've managed to insert using their superb tool.

  A few lines to illustrate along with your
  standard reference  might  be enough ....  

    https://wiki.python.org/moin/GoogleGroupsPython

>>>> 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!
 

-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

[toc] | [prev] | [next] | [standalone]


#62895

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-12-31 05:57 +1100
Message-ID<52c1c238$0$29986$c3e8da3$5496439d@news.astraweb.com>
In reply to#62890
Mark Lawrence wrote:

> On 30/12/2013 17:07, Cousin Stanley wrote:

[...]
>>> Would you please read and action this
>>> https://wiki.python.org/moin/GoogleGroupsPython
>>> to prevent us seeing the double line spacing above, thanks.
>>
>> You might consider either turning off an option
>> in your news client for including message in reply
>> and/or snipping all but a few lines for context
>> to prevent us from seeing the double line spacing
>> all over again .... :-)
>>
> 
> Great idea, 

Yes it is. It's a bloody brilliant idea. If only there were some sort of
delete or backspace key on the keyboard that would allow the person
replying to trim or snip excess quoting...


> but one slight snag is the poster then doesn't see how many 
> newlines they've managed to insert using their superb tool.

So what? Chances are that Google Groups will cleverly hide the quoting from
them anyway, which means that you're not demonstrating the problem to them,
you're just spamming the group with double-spaced, excessively quoted,
irrelevant text. Even if they see the quoted text, half a dozen lines is
more than enough to demonstrate the problem to any reasonable person, they
can extrapolate from that. If half a dozen quoted lines isn't enough to
persuade them to read the link, a million lines won't be.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#62817

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-12-27 13:14 -0500
Message-ID<mailman.4675.1388168085.18130.python-list@python.org>
In reply to#62804
On Fri, 27 Dec 2013 07:40:29 -0800 (PST), matt.doolittle33@gmail.com
declaimed the following:


>
>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!  

	Are you "print"ing the value?

>>> x = time.time(); print x, repr(x)
1388167958.83 1388167958.831
>>> x = time.time(); print x, repr(x)
1388167963.92 1388167963.919
>>> x = time.time(); print x, repr(x)
1388167967.23 1388167967.231


Note: this is on Windows, with its small fractional amount. Note that
printing the value rounds to 2 places.

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#62829

FromCameron Simpson <cs@zip.com.au>
Date2013-12-28 11:25 +1100
Message-ID<mailman.4682.1388190359.18130.python-list@python.org>
In reply to#62804
On 27Dec2013 07:40, matt.doolittle33@gmail.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!

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.

Cheers,
-- 
Cameron Simpson <cs@zip.com.au>

Try moving off NT easily.  You can move from Solaris to HP/UX to AIX or
DEC easily-- relative to moving off of NT, which is like a Roach
Motel.  Once you check in, you never check out.
        - Scott McNealy, Sun Microsystems

[toc] | [prev] | [next] | [standalone]


#62879

Frommatt.doolittle33@gmail.com
Date2013-12-29 18:44 -0800
Message-ID<a891e541-7764-4aa2-a614-a6bceecd953e@googlegroups.com>
In reply to#62829
On Friday, December 27, 2013 7:25:42 PM UTC-5, Cameron Simpson wrote:
> On 27Dec2013 07:40, matt.doolittle33@gmail.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!
> 
> 
> 
> 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?  

[toc] | [prev] | [next] | [standalone]


#62881

FromNed Batchelder <ned@nedbatchelder.com>
Date2013-12-30 07:50 -0500
Message-ID<mailman.4714.1388407860.18130.python-list@python.org>
In reply to#62879
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 <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

[toc] | [prev] | [next] | [standalone]


#62886

FromRoy Smith <roy@panix.com>
Date2013-12-30 09:22 -0500
Message-ID<roy-18A90D.09222130122013@news.panix.com>
In reply to#62881
In article <mailman.4714.1388407860.18130.python-list@python.org>,
 Ned Batchelder <ned@nedbatchelder.com> wrote:

> A float's str() includes two decimal points of precision

It's actually weirder than that.  What str() appears to do is print some 
variable number of digits after the decimal place, depending on the 
magnitude of the number, and then flips over to exponential notation at 
some point.  All of this is in line with str()'s intent, which is to 
produce a human-friendly string:

for i in range(15):
    f = 10**i + 0.123456789
    print "%-20s %-20s" % (str(f), repr(f))


$ python float.py
1.123456789          1.123456789         
10.123456789         10.123456789        
100.123456789        100.123456789       
1000.12345679        1000.123456789      
10000.1234568        10000.123456789     
100000.123457        100000.123456789    
1000000.12346        1000000.123456789   
10000000.1235        10000000.12345679   
100000000.123        100000000.12345679  
1000000000.12        1000000000.1234568  
10000000000.1        10000000000.123457  
1e+11                100000000000.12346  
1e+12                1000000000000.1234  
1e+13                10000000000000.123  
1e+14                100000000000000.12

It just happens that for the range of values time.time() is returning 
these days, two decimal digits is what you get.  Unix time rolled over 
to this many digits on

>>> time.ctime(999999999)
'Sat Sep  8 21:46:39 2001'

so before then, str(time.time()) would have (presumably) generated 3 
decimal digits.

Note that repr() also adjusts the number of digits after the decimal 
place, but this is because it's run out of available hardware precision 
(IEEE double precision is about 16 decimal digits).

Also note that while repr() is smart enough to stop when it runs out of 
bits, the %f format specifier isn't:

>>> f = 10000000000000.123456789
>>> repr(f)
'10000000000000.123'
>>> "%.6f" % f
'10000000000000.123047'

[Ned, again]
> Luckily, you can decide how to format the float yourself:
> [...]
>      >>> print "%.4f" % time.time()
>      1388407726.1001

The problem here is that you have no guarantee here that all those 
digits are meaningful.  I'm not sure what would happen on a machine 
where the system clock only gives centisecond precision.

I would like to think "%.4f" % time.time() would always produce a string 
with 4 digits after the decimal point, the last two of which were 
guaranteed to be "0".  But not having such a box handy to test, that's 
just a conjecture.  A much more pathological case would be that it 
produces random garbage for the extra digits, which would make it appear 
that you were getting more time precision than you really were.

All of which is a good reason to avoid raw timestamps and use datetime.  
With a datatime object, somebody else has already worried about these 
things for you.

PS: all the above examples were done with Python 2.7.1 on OSX 10.7.

[toc] | [prev] | [next] | [standalone]


#62882

FromNed Batchelder <ned@nedbatchelder.com>
Date2013-12-30 08:01 -0500
Message-ID<mailman.4715.1388408492.18130.python-list@python.org>
In reply to#62879
On 12/30/13 7:50 AM, Ned Batchelder wrote:
> 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.

Oops, and now Matt's reply to that message has just arrived! Sorry for 
the noise.

-- 
Ned Batchelder, http://nedbatchelder.com

[toc] | [prev] | [next] | [standalone]


#62883

Frommatt.doolittle33@gmail.com
Date2013-12-30 05:40 -0800
Message-ID<6a43f7fe-0757-4224-a1e7-8fe2ed67b9e4@googlegroups.com>
In reply to#62882
On Monday, December 30, 2013 8:01:21 AM UTC-5, Ned Batchelder wrote:
> On 12/30/13 7:50 AM, Ned Batchelder wrote:
> 
> > 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.
> 
> 
> 
> Oops, and now Matt's reply to that message has just arrived! Sorry for 
> 
> the noise.
> 
> 
> 
> -- 
> 
> Ned Batchelder, http://nedbatchelder.com

the formatting:
   self.logfile.write('%.6f\t'%(time.time()))

fixed it.  thank you very much.  

[toc] | [prev] | [next] | [standalone]


#62831

FromNed Batchelder <ned@nedbatchelder.com>
Date2013-12-27 21:10 -0500
Message-ID<mailman.4683.1388196666.18130.python-list@python.org>
In reply to#62804
On 12/27/13 7:25 PM, Cameron Simpson wrote:
> On 27Dec2013 07:40, matt.doolittle33@gmail.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!
>
> Repeatedly people have asked you to show your exact code. Still nothing.

Is something wrong with the connectivity of this list?  Matt posted his 
code about six hours before your message.

-- 
Ned Batchelder, http://nedbatchelder.com

[toc] | [prev] | [next] | [standalone]


#62832

FromSteven D'Aprano <steve@pearwood.info>
Date2013-12-28 03:50 +0000
Message-ID<52be4a79$0$2877$c3e8da3$76491128@news.astraweb.com>
In reply to#62831
On Fri, 27 Dec 2013 21:10:49 -0500, Ned Batchelder wrote:

> On 12/27/13 7:25 PM, Cameron Simpson wrote:
>> On 27Dec2013 07:40, matt.doolittle33@gmail.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!
>>
>> Repeatedly people have asked you to show your exact code. Still
>> nothing.
> 
> Is something wrong with the connectivity of this list?  Matt posted his
> code about six hours before your message.

Methinks too many people have been hitting the Christmas eggnog a little 
harder than is wise...

:-)




-- 
Steven

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web