Alias for an attribute defined in a superclass

Ben Finney ben+python at benfinney.id.au
Thu Mar 31 18:14:03 EDT 2011


Howdy all,

I want to inherit from a class, and define aliases for many of its
attributes. How can I refer to “the attribute that will be available by
name ‘spam’ once this class is defined”?

    class Foo(object):
        def spam(self):
            pass

        def eggs(self):
            pass

    class Bar(Foo):
        beans = Foo.spam
        mash = Foo.eggs

Is that the right way to do it? Will that leave me open to “unbound
method” or “is not an instance of ‘Bar’” or other problems when using
‘Bar.beans’?

-- 
 \           “If [a technology company] has confidence in their future |
  `\      ability to innovate, the importance they place on protecting |
_o__)     their past innovations really should decline.” —Gary Barnett |
Ben Finney



More information about the Python-list mailing list