need to print seconds from the epoch including the millisecond

Roy Smith roy at panix.com
Fri Dec 27 19:50:32 CET 2013


In article <1db0d993-9d2d-46af-9ee8-69d9250dc803 at googlegroups.com>,
 matt.doolittle33 at 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.



More information about the Python-list mailing list