[Tutor] question about metaclasses
Peter Otten
__peter__ at web.de
Mon Jan 15 09:40:41 EST 2018
Steven D'Aprano wrote:
> On Wed, Jan 10, 2018 at 07:29:58PM +0100, Peter Otten wrote:
>
> [...]
>> elif not isinstance(obj, property):
>> attrs[attr] = property(lambda self, obj=obj: obj)
>
>> PS: If you don't remember why the obj=obj is necessary:
>> Python uses late binding; without that trick all lambda functions would
>> return the value bound to the obj name when the for loop has completed.
>
> This is true, but I think your terminology is misleading. For default
> values to function parameters, Python uses *early* binding, not late
> binding: the default value is computed once at the time the function is
> created, not each time it is needed.
You are right; I should have stated clearly where I was talking about the
closure.
More information about the Tutor
mailing list