N
Ned Batchelder
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.
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.
matt@matt-Inspiron-1525:~$ pythonI am on Ubuntu 12.10. I am still working with the 2 decimalplaces. 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.
1388190100.44
1388190102.795531
Please show us _exactly_ what you're doing. I'm guessing that print
is confusing you.
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 importsimport sysimport posixpathimport timefrom time import strftimefrom datetime import datetimeimport osimport wximport cPickle as pickleimport gnuradio.gr.gr_threading as _threading
#the function that writes the time valuesdef update(self, field_values):
now = datetime.now()
#logger ---------------# new line to write on
# write date, time, and seconds from the epoch
# list to store dictionary keys in tis orderkeys = ["duid", "nac", "tgid", "source", "algid", "kid"]# loop through the keys in the right orderfor k in keys:# get the value of the current keyf = field_values.get(k, None)# if data unit has value...if f:# output the value with trailing tab
# if data unit doesnt have this value print a tab
#end logger ----------------
#if the field 'duid' == 'hdu', then clear fieldsif 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, vfor k,v in self.fields.items():# get the dict value for this TextCtrlf = field_values.get(k, None)# if the value is empty then set the new valueif f:
#sample output in a .txt file:
Instead of:
"%s" % time.time()
try:
"%.6f" % time.time()
%.6f is a formatting code meaning, floating-point number, 6 decimal places.
thanks a bunch. the "%.6f" was the cure. can you please point me to the doc for formatting time? Thanks!
matt@matt-Inspiron-1525:~$ pythonI am on Ubuntu 12.10. I am still working with the 2 decimalplaces. 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.
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.
i get the same result as you expect. so its got to be the write statement that is truncated the decimal places right?
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.
(e-mail address removed) 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 importsimport sysimport posixpathimport timefrom time import strftimefrom datetime import datetimeimport osimport wximport cPickle as pickleimport gnuradio.gr.gr_threading as _threading
#the function that writes the time valuesdef update(self, field_values):
now = datetime.now()
#logger ---------------# new line to write on
# write date, time, and seconds from the epoch
# list to store dictionary keys in tis orderkeys = ["duid", "nac", "tgid", "source", "algid", "kid"]# loop through the keys in the right orderfor k in keys:# get the value of the current keyf = field_values.get(k, None)# if data unit has value...if f:# output the value with trailing tab
# if data unit doesnt have this value print a tab
#end logger ----------------
#if the field 'duid' == 'hdu', then clear fieldsif 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, vfor k,v in self.fields.items():# get the dict value for this TextCtrlf = field_values.get(k, None)# if the value is empty then set the new valueif f:
#sample output in a .txt file:
Instead of:
"%s" % time.time()
try:
"%.6f" % time.time()
%.6f is a formatting code meaning, floating-point number, 6 decimal places.
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.
Ned Batchelder said:A float's str() includes two decimal points of precision
Luckily, you can decide how to format the float yourself:
[...]1388407726.1001
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.
Mark said:On 30/12/2013 17:07, Cousin Stanley wrote:
[...]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.
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.
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.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.