Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2321

Re: Alias for an attribute defined in a superclass

References <87sju3ndjo.fsf@benfinney.id.au>
From Calvin Spealman <ironfroggy@gmail.com>
Date 2011-03-31 20:36 -0400
Subject Re: Alias for an attribute defined in a superclass
Newsgroups comp.lang.python
Message-ID <mailman.57.1301618196.2990.python-list@python.org> (permalink)

Show all headers | View raw


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@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Alias for an attribute defined in a superclass Ben Finney <ben+python@benfinney.id.au> - 2011-04-01 09:14 +1100
  Re: Alias for an attribute defined in a superclass Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-01 00:14 +0000
    Re: Alias for an attribute defined in a superclass Ben Finney <ben+python@benfinney.id.au> - 2011-04-01 11:59 +1100
  Re: Alias for an attribute defined in a superclass Calvin Spealman <ironfroggy@gmail.com> - 2011-03-31 20:36 -0400
    Re: Alias for an attribute defined in a superclass Ben Finney <ben+python@benfinney.id.au> - 2011-04-01 11:57 +1100
  Re: Alias for an attribute defined in a superclass Raymond Hettinger <python@rcn.com> - 2011-03-31 19:24 -0700
    Re: Alias for an attribute defined in a superclass Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-04-01 11:54 +0200

csiph-web