Scope rule pecularities

Duncan Booth me at privacy.net
Wed May 12 08:02:21 EDT 2004


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.

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.



More information about the Python-list mailing list