a fairly ugly/kludgy way to get 'aliases' in Python

Jonathan P. jbperez808 at yahoo.com
Fri Jan 17 22:34:03 EST 2003


Cliff Wells <LogiplexSoftware at earthlink.net> wrote in message news:<mailman.1042827297.2914.python-list at python.org>...

> I don't think performance will be affected either way (it's all
> dictionary lookups).  Still, I wonder why you don't just use:
> 
> class A:
>     def __init__(self):
>         self.long_descriptive_name = 0
>         self.long_descriptive_name2 = 10
> 
>     def x(self):
>         alias1 = self.long_descriptive_name
>         alias2 = self.long_descriptive_name2
>         self.alias = alias2 * alias1
> 
> which would seem to be the equivalent, more readable form.

Ah but this won't work.  You need to do the D_[alias1]=newvalue
trick to get the value assigned to self.long_descriptive_name.
The behaviour is different and that's why I wonder if there
is a speed penalty involved.




More information about the Python-list mailing list