Compile time evaluation of dictionaries

Chris Rebert clp2 at rebertia.com
Thu Mar 10 19:27:17 EST 2011


On Thu, Mar 10, 2011 at 4:15 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> 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 be as bad as one"}
>>>
>>> could be evaluated at compile time, but is not:
>>
>> In fact, it could be evaluated at writing time ;-).
>
> True, but why do stuff when the compiler can do it for you?
<snip>
> I don't see any reason why Python couldn't optimize the above at compile-
> time, and I can only think of two reasons why it won't:
>
> - lack of interest from anyone willing and able to write a patch;
> - the added complexity may be more than the benefit gained.

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
)

Cheers,
Chris



More information about the Python-list mailing list