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


Groups > comp.lang.python > #53082

RE: Can a child access parent attributes if that child added post-hoc as an attribute to the parent?

From "Prasad, Ramit" <ramit.prasad@jpmorgan.com.dmarc.invalid>
Subject RE: Can a child access parent attributes if that child added post-hoc as an attribute to the parent?
Date 2013-08-27 18:38 +0000
References <14d50efb-e88b-4259-960a-97ef58e345d8@googlegroups.com> <5B80DD153D7D744689F57F4FB69AF47418683AD8@SCACMX008.exchad.jpmchase.net> <CALwzidk1jS3ZNWV9bEcojJF-mvxtU-E7hSoNe1K9QXzgY21N1w@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.277.1377628719.19984.python-list@python.org> (permalink)

Show all headers | View raw


Ian Kelly wrote:
> On Thu, Aug 22, 2013 at 3:26 PM, Prasad, Ramit
> <ramit.prasad@jpmorgan.com.dmarc.invalid> wrote:
> > Bitswapper wrote:
> >>
> >> So I have a parent and child class:
> >>
> >>
> >> class Map(object):
> >>     def __init__(self, name=''):
> >>         self.mapName = name
> >>         self.rules = {}
> >>
> >> class Rule(Map):
> >>     def __init__(self, number):
> >>         Map.__init__(self)
> >>         self.number = number
> >
> > This means that rules will never have a name. I think you need
> >       def __init__(self, name='', number=None):
> >           Map.__init__(self, name)
> >           self.number = number
> 
> No, that's still wrong.  The OP talks abut maps having names, not
> rules having names.  Unless a Rule is-a Map, which sounds unlikely,
> Rule should not be inheriting from Map in the first place.
> 

Good point. Composition definitely makes more sense as I was
confused by how the inheritance was supposed to work anyway. :)


~Ramit



This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email.  

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


Thread

Can a child access parent attributes if that child added post-hoc as an attribute to the parent? Bitswapper <bithead0101@gmail.com> - 2013-08-22 14:03 -0700
  RE: Can a child access parent attributes if that child added post-hoc as an attribute to the parent? "Prasad, Ramit" <ramit.prasad@jpmorgan.com.dmarc.invalid> - 2013-08-22 21:26 +0000
    Re: Can a child access parent attributes if that child added post-hoc as an attribute to the parent? Bitswapper <bithead0101@gmail.com> - 2013-08-22 15:00 -0700
      Re: Can a child access parent attributes if that child added post-hoc as an attribute to the parent? Bitswapper <bithead0101@gmail.com> - 2013-08-23 07:11 -0700
  Re: Can a child access parent attributes if that child added post-hoc as an attribute to the parent? Ian Kelly <ian.g.kelly@gmail.com> - 2013-08-22 15:59 -0600
    Re: Can a child access parent attributes if that child added post-hoc as an attribute to the parent? Bitswapper <bithead0101@gmail.com> - 2013-08-23 12:39 -0700
  RE: Can a child access parent attributes if that child added post-hoc as an attribute to the parent? "Prasad, Ramit" <ramit.prasad@jpmorgan.com.dmarc.invalid> - 2013-08-27 18:38 +0000

csiph-web