Alias for an attribute defined in a superclass
Raymond Hettinger
python at rcn.com
Thu Mar 31 22:24:42 EDT 2011
On Mar 31, 3:14 pm, Ben Finney <ben+pyt... at benfinney.id.au> 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.
Raymond
More information about the Python-list
mailing list