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

Cliff Wells clifford.wells at attbi.com
Sun Jan 19 05:10:36 CET 2003

On Fri, 2003-01-17 at 19:34, Jonathan P. wrote:
> 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.

Yes, after I posted this, I suddenly realized what you meant.  Then I
frantically tried to reverse time, to a few seconds before I hit the
send button, only to fail at that as well.  It seems I've lost my
superpowers and will be forced to actually read posts before replying to
them as I clearly can't rely on time-travel any more.  I'll probably
have to start wearing my tinfoil hat again too.


Cliff Wells <clifford.wells at attbi.com>

More information about the Python-list mailing list