Controlling assignation
Xavier Décoret
Xavier.Decoret at imag.fr
Tue Jun 14 03:25:11 EDT 2005
Bruno Desthuilliers a écrit :
> Xavier Décoret a écrit :
> (snip)
>
>> What I wanted to do is something like this:
>>
>> def change(x,v):
>> x = v
>>
>> class A(object):
>> def __init__(self,v):
>> self.x = v
>>
>> a = A(3)
>> print a.x # displays 3
>> change(a.x,4)
>> print a.x # still displays 3
>>
>>
>> It may seem weird,
>
>
> It does
>
>> but I ensure there is a reason for doing this.
>
>
> I really wonder what it can be ???
It's the ability to develop the equivalent of GeoNext (and much more) in
Python with a very nice syntax.
>
> You could achieve the same effect with:
>
> class A( object):
> def __init__(self, value):
> self.value = value
>
> a = A(3)
> a.value = 4
> a.value
> => 4
>
Of course, and even simpler ;-)
print "4"
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
> And it's *much* more simple/readable/efficient.
>
> Ever googled for "evolution of a programmer" ?-)
>
>
Not to brag, but I think I know what programming is. Google for my
name. C'est bien un commentaire de francais ca ;-)
More information about the Python-list
mailing list