Controlling assignation
Terry Reedy
tjreedy at udel.edu
Tue Jun 14 12:19:47 EDT 2005
"Xavier Décoret" <Xavier.Decoret at imag.fr> wrote in message
news:42AE8657.9070806 at imag.fr...
>> class A( object):
>> def __init__(self, value):
>> self.value = value
>More seriously, try to do this with your simpler approach.
>a = A(4)
>b = A(lambda : a.x+5)
>a.x = 2
>print b.x # I want this to be 7, not 9
As written, it will be neither, since b.x is a function. But if you call
it, its value *is* 7, not 9, as you specified wanting. So I don't
understand your point.
>>> class A:
... def __init__(self,val): self.x = val
...
>>> a = A(4)
>>> b = A(lambda : a.x+5)
>>> a.x=2
>>> b.x
<function <lambda> at 0x008D1650>
>>> b.x()
7
Terry J. Reedy
More information about the Python-list
mailing list