Thomas Rachel, 22.07.2011 10:08:
Am 22.07.2011 08:59 schrieb Frank Millman:

My guess is that it is something to do with the console, but I don't
know what. If I get time over the weekend I will try to get to the
bottom of it.

I would guess that in the first case, python (resp. timeit.py) gets the
intended code for execution: int(float('165.0')). I. e., give the string to
float() and its result to int().

In the second case, however, timeit.py gets the string
'int(float("165.0"))' and evaluates it - which is a matter of
sub-microseconds.

The reason for this is that the Windows "shell" removes the "" in the first
case, but not the '' in the second case.

Good call. Or maybe it actually gets the code 'int(float(165.0))' in the second case, so it doesn't need to parse the string into a float. But given the huge difference in the timings, I would second your guess that it just evaluates the plain string itself instead of the code.

Stefan

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to