Addressing the last element of a list

Peter Otten __peter__ at web.de
Tue Nov 8 05:13:22 EST 2005


Jerzy Karczmarczuk wrote:

> Peter Otten wrote:
>> pinkfloydhomer at gmail.com wrote:
>> 
>> 
>>>Just to satisfy my curiousity: Is there a way to do something like the
>>>reference solution I suggest above?
>> 
>> 
>> No. You cannot overload assignment.
> 
> I have the impression that this is not an issue, to overload assignments,
> which btw. *can* be overloaded, but the absence of *aliasing*
> (undiscriminate handling of pointers) in Python. Am I wrong?

I think so. 

a = b

will always make a a reference to (the same object as) b. What can be
overloaded is attribute assignment:

x.a = b

can do anything from creating an attribute that references b to wiping your
hard disk.

I don't understand what you mean by "absence of aliasing", but conceptually
every python variable is a -- well-behaved -- pointer.

Peter




More information about the Python-list mailing list