Scope rule pecularities
Antoon Pardon
apardon at forel.vub.ac.be
Wed May 12 08:31:29 EDT 2004
Op 2004-05-12, Duncan Booth schreef <me at privacy.net>:
> Antoon Pardon <apardon at forel.vub.ac.be> wrote in
> news:slrnca428q.1i9.apardon at trout.vub.ac.be:
>
>> IMO lacking an assignment that copies the value
>> of one object into another was a mistake and
>> which creats IMO a lot of difficulties.
>>
>> If I have a function with an object as a paramter.
>> and this object is mutable. Now within this function
>> I find a second object with the value I want the
>> argument to have. Now I can't simply copy the
>> second object over the argument but I have to
>> copy attribute by attribute from the second object
>> into the argument.
>
> Why wouldn't you just return the second value (or a copy of it) as a result
> from the function? That is usually a more flexible choice since it gives
> the caller the option of either replacing the original value or using the
> modified value somewhere different.
Well because the object could be bound with more than one name.
> Anyway, if you really need to do this then the mutable object should have
> some sort of updateState method which takes the second object as a
> parameter. That way the original object can have control over which
> attributes get overwritten and which don't.
And I think it is a pain in the butt to always have to write such an
UpdateState method whenever you want one object to be copied in place
from an other.
--
Antoon Pardon
More information about the Python-list
mailing list