Alias for an attribute defined in a superclass

Calvin Spealman ironfroggy at gmail.com
Thu Mar 31 20:36:09 EDT 2011


Sounds like you're just going to end up with more confusing code
having multiple ways to refer to the exact same thing. Why?

On Thu, Mar 31, 2011 at 6:14 PM, Ben Finney <ben+python 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? 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy



More information about the Python-list mailing list