Compile time evaluation of dictionaries

G

Gerald Britton

Jean-Michel Pichavan said:
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?
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top