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

Jonathan P. jbperez808 at yahoo.com
Fri Jan 17 00:52:58 CET 2003


class A:
  def __init__(self):
    self.long_descriptive_name=0
    self.long_descriptive_name2=10

  def x(self):
    D_=self.__dict__
    alias1='long_descriptive_name'
    alias2='long_descriptive_name2'
    D_[alias]=D_[alias2]*D_[alias1]
    # instead of self.long_descriptive_name =
    #  self.long_descriptive_name*self.long_descriptive_name2

Question: 
  Will the dictionary lookup 'D_[alias]' impose a
  performance penalty versus 'self.long_descriptive_name' or
  will the compiler do the same thing internally anyway in
  both cases?




More information about the Python-list mailing list