lambda in list comprehension acting funny

Terry Reedy tjreedy at udel.edu
Sun Jul 15 06:27:43 EDT 2012


On 7/15/2012 4:32 AM, Steven D'Aprano wrote:
> On Sun, 15 Jul 2012 10:49:48 +1000, Chris Angelico wrote:
>
>> On Sun, Jul 15, 2012 at 9:29 AM, Steven D'Aprano
>> <steve+comp.lang.python at pearwood.info> wrote:
>>> Not necessarily *compile* time, but the distinction is between when the
>>> function is defined (which may at compile time, or it may be at run
>>> time) versus when the function is called.
>>
>> I'd treat the def/lambda statement as "compile time" and the () operator
>> as "run time".
>
> But function definitions occur at run time, not compile time -- they are
> executable statements, not instructions to the compiler to define a
> function.

The () operator is 'call time'. The main points are
a) the execution of def statements and lambda expressions and the 
execution of calls happen at different run times.
b) default arg objects are calculated at def/lambda time.
c) names in def bodies and lambda expressions are resolved at call time.
and
d) people more often forget c) when thinking about lambda expressions 
that for def statements.

-- 
Terry Jan Reedy




More information about the Python-list mailing list