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

F

flamesrock

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?


(PS, I wasn't smoking anything, its a figure of speech :) )
 
C

Chris Mellon

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.
 
B

Bjoern Schliessmann

flamesrock said:
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..

C++ also wouldn't. How could multiple object instantiations be
atomic?

Regards,


Björn
 
G

Gabriel Genellina

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?

The only thing Python can guarantee, is that the left expression is
evaluated before the right one (5.13 Evaluation order, Language Reference).

Then, whether the first call yields a result always less (or equal)
to the second, is out of Python scope (and control).
(They might be equal if both calls get the same quantum of time; they
might be reversed if some other process sets the time in the past).


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 
B

Ben Finney

Gabriel Genellina said:
The only thing Python can guarantee, is that the left expression is
evaluated before the right one (5.13 Evaluation order, Language
Reference).

Thanks, that answers my question asked elsewhere.
 
A

AndyR

Hi all:

From my experience with os's.
Time is updated at intervals- they may be as low as 1mS See . So for that
millisecond multiple readings of the time will always return the same
result. Therefore time.time() < time.time() will be false for most readings.

However the result could be true if you catch the exact time when the os
updates its clock. It will only be True for a single execution of the line
and you will have to be lucky to catch it at just the right time.

Of course if you hard loop over the interval its possible to see the
transition.

for x in xrange (10000):
t = time.time()
if t < time.time:
print "transition at ", t

Enjoy.
Andy
 
H

Hendrik van Rooyen

8<----------------------------------
.... since the statement itself
occurs at one time instant..

nothing, but nothing, can occur at one time instant....

- Hendrik
 
T

Tim Roberts

Hendrik van Rooyen said:
8<----------------------------------


nothing, but nothing, can occur at one time instant....

Well, as long as we're being pedantic, surely that should read "only one
thing can occur at any time instant..."
 
H

Hendrik van Rooyen

Well, as long as we're being pedantic, surely that should read "only one
thing can occur at any time instant..."

No its worse than that - what I mean is that everything takes finite time...

:) Hendrik
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top