Is time.time() < time.time() always true?

Delaney, Timothy (Tim) tdelaney at avaya.com
Tue Nov 21 18:33:54 EST 2006


Chris Mellon wrote:

> On 21 Nov 2006 15:10:25 -0800, flamesrock <flamesrock at gmail.com>
> wrote: 
>> So, I was blazin' some mad chronix, as they say, and got on to
>> thinking about Python. 
>> 
>> The question was, is the statement:
>> 
>> time.time() < time.time()
>> 
>> always true? Seems it should be false, since the statement itself
>> occurs at one time instant.. but of course we know that python
>> doesn't execute code that way.. So my question is, why doesn't
>> Python work this way? 
>> 
> 
> This would only be false if the time between the 2 calls was less than
> the precision of the OS call that time.time uses.

So long as the clock on the machine it's running on is not set backwards
between the two calls, you can guarantee that

   time.time() <= time.time()

will always evaluate true.

However, it's always possible (though incredibly unlikely) that an
external process changes the clock between the two system calls that are
made.

Tim Delaney



More information about the Python-list mailing list