On Thu, 10 Mar 2011 11:23:32 -0500, Gerald Britton 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: [...] > 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.
Python is a language, what you are looking at is an implementation of that language. Although I have never used it myself, apparently Cesare Di Mauro's WPython does more constant folding optimizations than CPython. See pages 21-24 of http://wpython2.googlecode.com/files/Beyond%20Bytecode%20-%20A%20Wordcode-based%20Python.pdf -- Steven -- http://mail.python.org/mailman/listinfo/python-list