Re: need to print seconds from the epoch including the millisecond

2014-01-03 Thread Chris Angelico
On Sat, Jan 4, 2014 at 2:33 AM, Grant Edwards invalid@invalid.invalid wrote:
 time.time() returns a Python float. A Python float will have 16 digits
 of precision. Perhaps the OS always sets some of those digits to 0 (or
 even random values), but they're still there.  Perhaps the accuracy or
 granularity of the values returned is problematic on some OSes, but
 the precision of the value doesn't change: there's no way he's only
 getting 2 decimal places from time.time() unless (as you mention
 below) he's printing them using a method that truncates/rounds.

If I print out the value float(1.01), I get just three digits. When
those trailing digits are all zeroes, they won't be displayed. That's
exactly what the OP was seeing.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2014-01-03 Thread Grant Edwards
On 2014-01-03, Dave Angel da...@davea.name wrote:
 On Thu, 2 Jan 2014 16:23:22 + (UTC), Grant Edwards 
invalid@invalid.invalid wrote:
 AFAIK, that's irrelevent.  time.time() returns a float.  On all the
 CPython implementations I know of, that is a 64-bit IEEE format, 
 which provides 16 decimal digits of precision regardless of the 
 granularity of the system time value.  At this point in time, that
 means 10 digits left of the decimal point and 6 to the right.

 Correction: no more than about 6 to the right.  You can certainly get 
 less, from an os with a smaller resolution.

time.time() returns a Python float. A Python float will have 16 digits
of precision. Perhaps the OS always sets some of those digits to 0 (or
even random values), but they're still there.  Perhaps the accuracy or
granularity of the values returned is problematic on some OSes, but
the precision of the value doesn't change: there's no way he's only
getting 2 decimal places from time.time() unless (as you mention
below) he's printing them using a method that truncates/rounds.

 Or you can lose some of what you do get by printing in a sub-optimal
 way.

Yes, depending on how you print the value, you can hide some of the
digits.  But, there's no way for time.time() to return a value with
less than ~16 decimal digits of precicsion.

-- 
Grant Edwards   grant.b.edwardsYow! !  Everybody out of
  at   the GENETIC POOL!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2014-01-02 Thread Grant Edwards
On 2013-12-26, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 matt.doolittl...@gmail.com wrote:

 On Thursday, December 26, 2013 2:22:10 PM UTC-5, Dan Stromberg wrote:
 On Thu, Dec 26, 2013 at 10:32 AM,  matt.doolittl...@gmail.com wrote:
 
  i am using 2.7.   I need to print the time in seconds from the epoch
  with millisecond precision.  i have tried many things but have failed. 
 [...]
 In [1]: import time
 In [2]: time.time()
 Out[2]: 1388085670.1567955

 
 OK i did what you said but I am only getting 2 decimal places.
 Why is this and what can I do to get the millisecond?

 Please show *exactly* what you did. Also please tell us what operating
 system you are using. It may be that your operating system's clock doesn't
 provide millisecond precision.

AFAIK, that's irrelevent.  time.time() returns a float.  On all the
CPython implementations I know of, that is a 64-bit IEEE format, which
provides 16 decimal digits of precision regardless of the granularity
of the system time value.  At this point in time, that means 10 digits
left of the decimal point and 6 to the right.

-- 
Grant Edwards   grant.b.edwardsYow! Will the third world
  at   war keep Bosom Buddies
  gmail.comoff the air?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2014-01-02 Thread Dave Angel
On Thu, 2 Jan 2014 16:23:22 + (UTC), Grant Edwards 
invalid@invalid.invalid wrote:

AFAIK, that's irrelevent.  time.time() returns a float.  On all the
CPython implementations I know of, that is a 64-bit IEEE format, 

which
provides 16 decimal digits of precision regardless of the 

granularity
of the system time value.  At this point in time, that means 10 

digits

left of the decimal point and 6 to the right.


Correction: no more than about 6 to the right.  You can certainly get 
less, from an os with a smaller resolution.  Or you can lose some of 
what you do get by printing in a sub-optimal way.


--
DaveA

--
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-30 Thread matt . doolittle33
On Friday, December 27, 2013 7:25:42 PM UTC-5, Cameron Simpson wrote:
 On 27Dec2013 07:40, matt.doolittl...@gmail.com matt.doolittl...@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?  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-30 Thread matt . doolittle33
On Friday, December 27, 2013 1:49:54 PM UTC-5, Ned Batchelder wrote:
 On 12/27/13 1:09 PM, matt.doolittl...@gmail.com wrote:
 
  On Friday, December 27, 2013 11:27:58 AM UTC-5, Roy Smith wrote:
 
  In article 0c33b7e4-edc9-4e1e-b919-fec210c92...@googlegroups.com,
 
 
 
matt.doolittl...@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:331388164053.18
 
  2013-12-27  12:07:331388164053.36
 
  2013-12-27  12:07:331388164053.54
 
  2013-12-27  12:07:331388164053.73
 
  2013-12-27  12:07:331388164053.91
 
  2013-12-27  12:07:341388164054.11
 
  2013-12-27  12:07:341388164054.28
 
  2013-12-27  12:07:341388164054.48
 
  2013-12-27  12:07:341388164054.66
 
  2013-12-27  12:07:341388164054.84
 
  2013-12-27  12:07:371388164057.62
 
  2013-12-27  12:07:371388164057.81
 
  2013-12-27  12:07:371388164057.99
 
  2013-12-27  12:07:381388164058.18
 
  2013-12-27  12:07:381388164058.37
 
  2013-12-27  12:07:381388164058.54
 
  2013-12-27  12:07:381388164058.73
 
  2013-12-27  12:07:381388164058.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!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-30 Thread Ned Batchelder

On 12/29/13 9:44 PM, matt.doolittl...@gmail.com wrote:

On Friday, December 27, 2013 7:25:42 PM UTC-5, Cameron Simpson wrote:

On 27Dec2013 07:40, matt.doolittl...@gmail.com matt.doolittl...@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

--
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-30 Thread Ned Batchelder

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

--
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-30 Thread matt . doolittle33
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.  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-30 Thread Mark Lawrence

On 30/12/2013 12:16, matt.doolittl...@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.doolittl...@gmail.com wrote:


On Friday, December 27, 2013 11:27:58 AM UTC-5, Roy Smith wrote:



In article 0c33b7e4-edc9-4e1e-b919-fec210c92...@googlegroups.com,







   matt.doolittl...@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:331388164053.18



2013-12-27  12:07:331388164053.36



2013-12-27  12:07:331388164053.54



2013-12-27  12:07:331388164053.73



2013-12-27  12:07:331388164053.91



2013-12-27  12:07:341388164054.11



2013-12-27  12:07:341388164054.28



2013-12-27  12:07:341388164054.48



2013-12-27  12:07:341388164054.66



2013-12-27  12:07:341388164054.84



2013-12-27  12:07:371388164057.62



2013-12-27  12:07:371388164057.81



2013-12-27  12:07:371388164057.99



2013-12-27  12:07:381388164058.18



2013-12-27  12:07:381388164058.37



2013-12-27  12:07:381388164058.54



2013-12-27  12:07:381388164058.73



2013-12-27  12:07:381388164058.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

--
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-30 Thread Roy Smith
In article mailman.4714.1388407860.18130.python-l...@python.org,
 Ned Batchelder n...@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.123456789100.123456789   
1000.123456791000.123456789  
1.12345681.123456789 
10.12345710.123456789
100.12346100.123456789   
1000.12351000.12345679   
1.1231.12345679  
10.1210.1234568  
100.1100.123457  
1e+111000.12346  
1e+121.1234  
1e+1310.123  
1e+14100.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(9)
'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 = 10.123456789
 repr(f)
'10.123'
 %.6f % f
'10.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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-30 Thread Cousin Stanley

 On 30/12/2013 12:16, matt.doolittl...@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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-30 Thread Mark Lawrence

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



On 30/12/2013 12:16, matt.doolittl...@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

--
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-30 Thread Cousin Stanley

 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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-30 Thread Steven D'Aprano
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

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread matt . doolittle33
On Thursday, December 26, 2013 8:29:15 PM UTC-5, Roy Smith wrote:
 In article 59aa73ac-e06e-4c0e-83a4-147ac42ca...@googlegroups.com,
 
  matt.doolittl...@gmail.com wrote:
 
 
 
   In [1]: import time
 
   In [2]: time.time()
 
   Out[2]: 1388085670.1567955
 
  
 
  OK i did what you said but I am only getting 2 decimal places.  
 
  Why is this and what can I do to get the millisecond?  
 
 
 
 What operating system are you on?  The Python time routines can only 
 
 return as much precision as the operating system makes available.

I use Ubuntu 12.10.  Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread matt . doolittle33
 I pretty much stopped using Windows 4 
 
 years ago.
 
I got off the plantation over a year ago and have not looked back. 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread matt . doolittle33
On Thursday, December 26, 2013 11:54:41 PM UTC-5, Dave Angel wrote:
 On Thu, 26 Dec 2013 20:03:34 -0500, Terry Reedy tjre...@udel.edu 
 
 wrote:
 
  On 12/26/2013 5:48 PM, Dave Angel wrote:
 
   You're probably on Windows,  which does time differently.
 
 
 
  With 3.3 and 3.4 on Windows 7, time.time() gives 6 fractional 
 
 digits.
 
import time; time.time()
 
  1388105935.971099
 
 
 
  With 2.7, same machine, I only get 3.
 
 
 
 The way I recall it,  Windows time is a mess. To get better than 10 
 
 ms resolution you needed to use time.clock, but that isn't epoch 
 
 time. Trickier solutions existed, depending on exactly what the 
 
 problem was. But judging from your test, 3.3 built those gyrations 
 
 into the stdlib. I dunno,  I pretty much stopped using Windows 4 
 
 years ago.
 
 
 
 -- 
 
 DaveA

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!  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Dave Angel
On Fri, 27 Dec 2013 07:40:29 -0800 (PST), matt.doolittl...@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!


Now I'm stumped.  2.7.3 on Ubuntu 12.04 and time.time gives me 6 
decimals. Of course it's a float, so you could get more or fewer. But 
if you're only seeing 2, something else is different.


--
DaveA

--
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Roy Smith
In article 0c33b7e4-edc9-4e1e-b919-fec210c92...@googlegroups.com,
 matt.doolittl...@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:

cat /etc/lsb-release

uname -a

python --version

cat prog.py

python prog.py
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread matt . doolittle33
On Friday, December 27, 2013 11:27:58 AM UTC-5, Roy Smith wrote:
 In article 0c33b7e4-edc9-4e1e-b919-fec210c92...@googlegroups.com,
 
  matt.doolittl...@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:331388164053.18
2013-12-27  12:07:331388164053.36
2013-12-27  12:07:331388164053.54
2013-12-27  12:07:331388164053.73
2013-12-27  12:07:331388164053.91
2013-12-27  12:07:341388164054.11
2013-12-27  12:07:341388164054.28
2013-12-27  12:07:341388164054.48
2013-12-27  12:07:341388164054.66
2013-12-27  12:07:341388164054.84
2013-12-27  12:07:371388164057.62
2013-12-27  12:07:371388164057.81
2013-12-27  12:07:371388164057.99
2013-12-27  12:07:381388164058.18
2013-12-27  12:07:381388164058.37
2013-12-27  12:07:381388164058.54
2013-12-27  12:07:381388164058.73
2013-12-27  12:07:381388164058.92

Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Ned Batchelder

On 12/27/13 1:09 PM, matt.doolittl...@gmail.com wrote:

On Friday, December 27, 2013 11:27:58 AM UTC-5, Roy Smith wrote:

In article 0c33b7e4-edc9-4e1e-b919-fec210c92...@googlegroups.com,

  matt.doolittl...@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:331388164053.18
2013-12-27  12:07:331388164053.36
2013-12-27  12:07:331388164053.54
2013-12-27  12:07:331388164053.73
2013-12-27  12:07:331388164053.91
2013-12-27  12:07:341388164054.11
2013-12-27  12:07:341388164054.28
2013-12-27  12:07:341388164054.48
2013-12-27  12:07:341388164054.66
2013-12-27  12:07:341388164054.84
2013-12-27  12:07:371388164057.62
2013-12-27  12:07:371388164057.81
2013-12-27  12:07:371388164057.99
2013-12-27  12:07:381388164058.18
2013-12-27  12:07:381388164058.37
2013-12-27  12:07:381388164058.54
2013-12-27  12:07:381388164058.73
2013-12-27  12:07:381388164058.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

--
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Roy Smith
In article 1db0d993-9d2d-46af-9ee8-69d9250dc...@googlegroups.com,
 matt.doolittl...@gmail.com wrote:

  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.

Why can't you run it that way?  What does got nothing mean?  Did you 
just get another shell prompt back with no output?  Did your shell 
window close?  Did the machine crash?

I asked you to run these commands:

 cat /etc/lsb-release
 
 uname -a
 
 python --version

Did you run them?  What output did you get?  I know it seems silly, but 
it really is important that people know exactly what your environment 
is.  The less information we have, the harder it is to figure out what's 
going on.

 but here is all the code relevant to this issue:

Well, you've got a lot of code there.  What you want to do is reduce 
this down to the smallest possible amount of code which demonstrates the 
problem.

I can't even begin to run your code here because I don't have gnuradio 
installed.  It's almost certainly not necessary to demonstrate the 
problem (nor are posixpath, cPickle, wx, etc), but I can already see 
that as soon as I delete those, I'll run up against the next problem, 
which is that update() is a method of a class and I don't have the rest 
of that class.

Let's take this one step at a time.  You've got:

self.logfile.write('%s\t'%(time.time()))

which is apparently causing, 1388164053.18, to end up in your output 
file.  The question is, why are there only two digits after the decimal 
place?  Possible causes:

1) Your version of time.time() is returning a float which is only 
precise to the centisecond.

2) Your version of string's %s operator is only converting floats to two 
decimal places.

3) Your self.logfile.write() method is taking the string it was given 
and stripping off all the digits beyond two after the decimal point.

All of those seem about equally unlikely, so just start to eliminate 
them one by one.  What happens if you do:

self.logfile.write(1388164053.183454)

What happens if you do:

t = time.time()
self.logfile.write(str=%s, repr=%s, (str(t), repr(t)))

what happens if you get rid of the whole self.logfile.write() thing and 
just use print?  If you're working in some environment where stdout gets 
redirected somewhere that you can't find, bypass stdout completely:

my_file = open(/tmp/foo, w)
print  my_file, time.time()

and then go look and see what got dropped into /tmp/foo.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Roy Smith
In article roy-4a275d.13503227122...@news.panix.com,
 Roy Smith r...@panix.com wrote:

 self.logfile.write(str=%s, repr=%s, (str(t), repr(t)))

Ugh, make that:

 self.logfile.write(str=%s, repr=%s % ((str(t), repr(t)))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Cameron Simpson
On 27Dec2013 07:40, matt.doolittl...@gmail.com matt.doolittl...@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 c...@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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Roy Smith
matt.doolittl...@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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Ned Batchelder

On 12/27/13 7:25 PM, Cameron Simpson wrote:

On 27Dec2013 07:40, matt.doolittl...@gmail.com matt.doolittl...@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

--
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-27 Thread Steven D'Aprano
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.doolittl...@gmail.com
 matt.doolittl...@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
-- 
https://mail.python.org/mailman/listinfo/python-list


need to print seconds from the epoch including the millisecond

2013-12-26 Thread matt . doolittle33
i am using 2.7.   I need to print the time in seconds from the epoch with 
millisecond precision.  i have tried many things but have failed.  heres my 
latest:

from time import time, strftime
from datetime import datetime, time

#  write date, time, then seconds from 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'%(now.time()))


what am i doing wrong?  what should i be doing here?  Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-26 Thread Dan Stromberg
On Thu, Dec 26, 2013 at 10:32 AM,  matt.doolittl...@gmail.com wrote:
 i am using 2.7.   I need to print the time in seconds from the epoch with 
 millisecond precision.  i have tried many things but have failed.  heres my 
 latest:

 from time import time, strftime
 from datetime import datetime, time

 #  write date, time, then seconds from 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'%(now.time()))

In [1]: import time

In [2]: time.time()
Out[2]: 1388085670.1567955

HTH
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-26 Thread matt . doolittle33
On Thursday, December 26, 2013 2:22:10 PM UTC-5, Dan Stromberg wrote:
 On Thu, Dec 26, 2013 at 10:32 AM,  matt.doolittl...@gmail.com wrote:
 
  i am using 2.7.   I need to print the time in seconds from the epoch with 
  millisecond precision.  i have tried many things but have failed.  heres my 
  latest:
 
 
 
  from time import time, strftime
 
  from datetime import datetime, time
 
 
 
  #  write date, time, then seconds from 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'%(now.time()))
 
 
 
 In [1]: import time
 
 
 
 In [2]: time.time()
 
 Out[2]: 1388085670.1567955
 
 
 
 HTH

OK i did what you said but I am only getting 2 decimal places.  
Why is this and what can I do to get the millisecond?  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-26 Thread Steven D'Aprano
matt.doolittl...@gmail.com wrote:

 On Thursday, December 26, 2013 2:22:10 PM UTC-5, Dan Stromberg wrote:
 On Thu, Dec 26, 2013 at 10:32 AM,  matt.doolittl...@gmail.com wrote:
 
  i am using 2.7.   I need to print the time in seconds from the epoch
  with millisecond precision.  i have tried many things but have failed. 
[...]
 In [1]: import time
 In [2]: time.time()
 Out[2]: 1388085670.1567955

 
 OK i did what you said but I am only getting 2 decimal places.
 Why is this and what can I do to get the millisecond?

Please show *exactly* what you did. Also please tell us what operating
system you are using. It may be that your operating system's clock doesn't
provide millisecond precision.



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-26 Thread Dave Angel
On Thu, 26 Dec 2013 14:06:17 -0800 (PST), matt.doolittl...@gmail.com 
wrote:
On Thursday, December 26, 2013 2:22:10 PM UTC-5, Dan Stromberg 

wrote:

 In [1]: import time
 In [2]: time.time()
 Out[2]: 1388085670.1567955


OK i did what you said but I am only getting 2 decimal places.  


You're probably on Windows,  which does time differently.  Specify 
your os version and python version and somebody will probably know.


--
DaveA

--
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-26 Thread Terry Reedy

On 12/26/2013 5:48 PM, Dave Angel wrote:

On Thu, 26 Dec 2013 14:06:17 -0800 (PST), matt.doolittl...@gmail.com wrote:

On Thursday, December 26, 2013 2:22:10 PM UTC-5, Dan Stromberg

wrote:

 In [1]: import time
 In [2]: time.time()
 Out[2]: 1388085670.1567955



OK i did what you said but I am only getting 2 decimal places.


You're probably on Windows,  which does time differently.


With 3.3 and 3.4 on Windows 7, time.time() gives 6 fractional digits.
 import time; time.time()
1388105935.971099

 Specify your os version and python version and somebody will probably 
know.


With 2.7, same machine, I only get 3.

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-26 Thread Roy Smith
In article 59aa73ac-e06e-4c0e-83a4-147ac42ca...@googlegroups.com,
 matt.doolittl...@gmail.com wrote:

  In [1]: import time
  In [2]: time.time()
  Out[2]: 1388085670.1567955
 
 OK i did what you said but I am only getting 2 decimal places.  
 Why is this and what can I do to get the millisecond?  

What operating system are you on?  The Python time routines can only 
return as much precision as the operating system makes available.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need to print seconds from the epoch including the millisecond

2013-12-26 Thread Dave Angel
On Thu, 26 Dec 2013 20:03:34 -0500, Terry Reedy tjre...@udel.edu 
wrote:

On 12/26/2013 5:48 PM, Dave Angel wrote:
 You're probably on Windows,  which does time differently.


With 3.3 and 3.4 on Windows 7, time.time() gives 6 fractional 

digits.

  import time; time.time()
1388105935.971099



With 2.7, same machine, I only get 3.


The way I recall it,  Windows time is a mess. To get better than 10 
ms resolution you needed to use time.clock, but that isn't epoch 
time. Trickier solutions existed, depending on exactly what the 
problem was. But judging from your test, 3.3 built those gyrations 
into the stdlib. I dunno,  I pretty much stopped using Windows 4 
years ago.


--
DaveA

--
https://mail.python.org/mailman/listinfo/python-list