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 -- http://mail.python.org/mailman/listinfo/python-list