Compile time evaluation of dictionaries
Gerald Britton
gerald.britton at gmail.com
Mon Mar 14 10:21:04 EDT 2011
Jean-Michel Pichavan wrote:
>> Today I noticed that an expression like this:
>>
>> "one:%(one)s two:%(two)s" % {"one": "is the loneliest number", "two":
>> "can be as bad as one"}
>>
>> could be evaluated at compile time, but is not:
>>
>>
[snip]
>> Any idea why Python works this way? I see that, in 3.2, an
>> optimization was done for sets (See "Optimizations" at
>> http://docs.python.org/py3k/whatsnew/3.2.html) though I do not see
>> anything similar for dictionaries.
>
>1/ because no one would ever see the difference.
The same thing could be said about sets, yet a similar optimization
was added to 3.2
>2/ immutables can always be evaluated before any high CPU consuming loop
immutables could also be evaluated at compile time, which would
obviate any such concern.
>3/ it would make the implementation more complex (i.e. more work for our
>beloved active community) for no gain
See my reply to 1/ above.
>4/ you can write C code to speed up things:
>http://docs.python.org/extending/extending.html, when really needed.
How do you spell red herring?
--
Gerald Britton
More information about the Python-list
mailing list