Modifying Class Object

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Feb 11 20:14:04 EST 2010


On Thu, 11 Feb 2010 23:26:34 +0100, Alf P. Steinbach wrote:

>> I presume you agree that the name 'Alf P. Steinbach' refers to you. Do
>> you then consider it to be a 'reference' to you?
> 
> Yes, and that's irrelevant, because you can't change a name.

Pardon me, but you most certainly can. Even Germany, which doesn't allow 
people to change their legal name for frivolous reasons, makes exceptions 
and will allow people to change their name if (e.g.) they have a sex 
change, or if they are burdened with a name that causes them ridicule, 
and presumably for their equivalent of the witness relocation program. 
And even Germany doesn't presume to tell people what name they are known 
by to their friends and family.

In Python, one can't change names *in place*, because strings are 
immutable. (Although I have seen a hack with ctypes which allows you to 
modify string objects. It makes a nice trick, but is completely useless 
because of the side-effects.) Even if you could modify the name, that 
would break the namespace it was stored in. But of course you can change 
names in two steps:

x = something()
y = x
del x

And lo, we have changed the name x to y.



-- 
Steven



More information about the Python-list mailing list