Alias for an attribute defined in a superclass

Raymond Hettinger python at
Fri Apr 1 04:24:42 CEST 2011

On Mar 31, 3:14 pm, Ben Finney <ben+pyt... at> wrote:
> 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?

For methods, that will work just fine.  For attributes, you will need
to make @property accessors that get and set the underlying attribute.


More information about the Python-list mailing list