Re: Compile time evaluation of dictionaries

2011-03-14 Thread Terry Reedy
On 3/14/2011 10:21 AM, Gerald Britton wrote: 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 s

Compile time evaluation of dictionaries

2011-03-14 Thread Gerald Britton
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,

Re: Compile time evaluation of dictionaries

2011-03-14 Thread Jean-Michel Pichavant
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: dis(compile( ... '"one:%(one)s two:%(two)s" % {"one": "is the lonelies

Re: Compile time evaluation of dictionaries

2011-03-11 Thread Steven D'Aprano
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

Re: Compile time evaluation of dictionaries

2011-03-11 Thread John Nagle
On 3/10/2011 8:23 AM, 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: CPython barely evaluates anything at compile time.

Re: Compile time evaluation of dictionaries

2011-03-10 Thread Steven D'Aprano
On Thu, 10 Mar 2011 16:27:17 -0800, Chris Rebert wrote: > 3. %-formatting is "obsolete and may go away in future versions of > Python." (See > http://docs.python.org/py3k/library/stdtypes.html#old-string-formatting- operations > ) There is an awful lot of opposition to that. If it ever happens,

Re: Compile time evaluation of dictionaries

2011-03-10 Thread Chris Rebert
On Thu, Mar 10, 2011 at 4:15 PM, Steven D'Aprano wrote: > On Thu, 10 Mar 2011 17:40:40 -0500, Terry Reedy wrote: >> On 3/10/2011 11:23 AM, Gerald Britton wrote: >>> Today I noticed that an expression like this: >>> >>> "one:%(one)s two:%(two)s" % {"one": "is the loneliest number", "two": >>> "can

Re: Compile time evaluation of dictionaries

2011-03-10 Thread Steven D'Aprano
On Thu, 10 Mar 2011 17:40:40 -0500, Terry Reedy wrote: > On 3/10/2011 11:23 AM, 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, bu

Re: Compile time evaluation of dictionaries

2011-03-10 Thread Terry Reedy
On 3/10/2011 11:23 AM, 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: In fact, it could be evaluated at writing time ;-). This wou

Compile time evaluation of dictionaries

2011-03-10 Thread Gerald Britton
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: >>> dis(compile( ... '"one:%(one)s two:%(two)s" % {"one": "is the loneliest number", "two": "can be as bad a