need to print seconds from the epoch including the millisecond

Roy Smith roy at panix.com
Fri Dec 27 20:15:33 EST 2013


matt.doolittle33 at 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.



More information about the Python-list mailing list