Generarl programming question.

Thomas 'PointedEars' Lahn PointedEars at web.de
Sun Apr 12 00:05:18 CEST 2015


Terry Reedy wrote:

> On 4/11/2015 3:19 PM, Thomas 'PointedEars' Lahn wrote:
>> Terry Reedy wrote:
>>> What Chris is describing is one local namespace (sheet of paper) per
>>> function *call*.
>> I *know* what he is describing: the *call* stack.
> 
> My comment above was directed not at you specifically but at the OP,
> Jonas, […]

ACK

>> The variable $bar then keeps its last value for subsequent calls of
>> foo().
> 
> In Python, one can do something similar with attributes, except that
> attributes are easily accessible from outside the function.

AISB.  Python’s “attributes” are named “properties” elsewhere.

> Mutable defaults probably come closer.
> 
> def doubler(_val=[1])"
>    _val[0] *= 2
>    return _val[0]
> 
> print(doubler(), doubler(), doubler())
> # 2 4 8

Fascinating.  Thanks.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.



More information about the Python-list mailing list