Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'output': 0.05; 'class,': 0.07; 'completeness': 0.07; 'advance': 0.07; '"__main__":': 0.09; '__name__': 0.09; 'received:155': 0.09; 'python': 0.11; 'def': 0.12; 'class:': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'name)': 0.16; "name=''):": 0.16; 'received:155.180': 0.16; 'received:159': 0.16; 'received:159.53': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'rule.': 0.16; 'securities,': 0.16; 'subject: \n ': 0.16; 'subject:access': 0.16; 'subject:post': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'thoughts': 0.19; 'seems': 0.21; '>>>': 0.22; 'example': 0.22; 'rules': 0.22; 'to:name:python-list@python.org': 0.22; 'print': 0.22; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'tried': 0.27; "doesn't": 0.30; "i'm": 0.30; 'subject:that': 0.31; 'class': 0.32; 'received:169.254': 0.32; 'skip:_ 10': 0.34; 'subject:the': 0.34; "i'd": 0.34; 'but': 0.35; 'really': 0.36; 'accuracy': 0.36; 'doing': 0.36; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'subject:?': 0.36; 'received:169': 0.37; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'subject:Can': 0.60; 'information,': 0.61; 'name': 0.63; 'skip:n 10': 0.64; 'for:': 0.64; 'map': 0.64; 'provide': 0.64; 'purchase': 0.65; 'occur': 0.65; 'to:addr:gmail.com': 0.65; 'subject': 0.69; 'legal': 0.71; 'sale': 0.75; 'number):': 0.84; 'received:169.254.8': 0.84 X-DKIM: OpenDKIM Filter v2.1.3 sz2.jpmchase.com r7MLQQXW006702 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1377206786; bh=6LY/coJuORn9hxM2fCFgBeKPqt9GvRwL2qHNN3jspls=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:content-transfer-encoding:MIME-Version; b=LgnJy+3yFRjsvT5ykVx/9sYJ+cSHdfZqWxXjD+op87wJ1Q/Dy398WFfNBdoj16y4T 2E96kDA6koOf9cxsDrPwbkxokTX65oCJKseGM/ACejPW9QYEYECjKLoF64q/wuA4hm AP8YPNh2wo7Sdp1/Bsq2rUXyOrBbi+6OUPOE4HWQ= X-AuditID: a959dcaa-b7f108e0000043ce-5a-5216820105a0 From: "Prasad, Ramit" To: Bitswapper , "python-list@python.org" Subject: RE: Can a child access parent attributes if that child added post-hoc as an attribute to the parent? Thread-Topic: Can a child access parent attributes if that child added post-hoc as an attribute to the parent? Thread-Index: AQHOn3tOhFqwvbYDS0+kAqnYoqz0KpmhuL5Q Date: Thu, 22 Aug 2013 21:26:24 +0000 References: <14d50efb-e88b-4259-960a-97ef58e345d8@googlegroups.com> In-Reply-To: <14d50efb-e88b-4259-960a-97ef58e345d8@googlegroups.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.67.79.47] Content-Type: text/plain; charset="us-ascii" content-transfer-encoding: quoted-printable MIME-Version: 1.0 X-DLP-FWD: Yes X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJKsWRmVeSWpSXmKPExsWyMlAiXZexSSzI4EOHvEXzmZ1MFkdar7E6 MHnsnHWX3ePF/DdsAUxRDYw2iXl5+SWJJakKKanFybZKLpnFyTmJmbmpRQq6Cl4FuflF6Yl5 esn5uUoKmSm2SiZKCgU5icmpual5JbZKiQUFqXkpSnZcChjABqgsM08hNS85PyUzL91WyTPY X9fCwtRS11DJLiQjs1ghNTcxM0chYSN7xsI3hgVt/BVNv26zNzB2cHcxcnJICJhIvN98jg3C FpO4cG89kM3FISRwhFFi3+XrLBDOIUaJOW1zGSGczYwS6y//YQJpYRMwlDh+9gk7iC0iEC0x fepTFhBbWCBfYnH3J1aIeIHEsqsPmCFsI4nt81vB1rEIqErMvNrLCGLzCoRIbJm7HCjOAbTA WaK/lQ8kzCngItG7Yg9YKyPQdd9PrQFbyywgLnHryXwmiKsFJJbsOc8MYYtKvHz8jxXClpd4 MeUlG0S9jsSC3Z+gbG2JZQtfM0OsFZQ4OfMJC8RaNYl9621BTAkBPontbdUTGCVmIVk2C8mg WUgGzUIyaAEjyypGyeLc9CxDveKyIr3SYr2sgtzkjMTiVL281JJNjKAUE3ln1Q7GZd22hxgF OBiVeHgnOIsFCbEmlhVX5gLDmYNZSYS3cdPGQCHelMTKqtSi/Pii0pzU4kOMVcAgm8gsJZqc D0x/eSXxhsZmFgampoYGFoZGJlQRVhLn3ZnLHSQkkA5MqNmpqQWpRTDLmTg4pRoY7Q7NF3++ llUp0PTR64udPSpuO2415q82vrn03qI/12c9DpdW07D2zeSTm3hjQTznnWeVbTFTuQpE59fx cj4UaJ42i4dP7ty6dzryOsaGWk6aYZJVgbEnkva6twpoPD7jcPBrrO0i6b5Jh7mvP1VQ2HCO 5aNuefGUPg/56TUHXC8rL5g09aKSEktxRqKhFnNRcSIAtTHUlIwDAAA= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 85 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377207491 news.xs4all.nl 16000 [2001:888:2000:d::a6]:47404 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52846 Bitswapper wrote: > > So I have a parent and child class: > > > class Map(object): > def __init__(self, name=3D''): > self.mapName =3D name > self.rules =3D {} > > class Rule(Map): > def __init__(self, number): > Map.__init__(self) > self.number =3D number This means that rules will never have a name. I think you need def __init__(self, name=3D'', number=3DNone): Map.__init__(self, name) self.number =3D number > > def __repr__(self): > return "Map " + self.mapName + " rule number " + str(self.number) > > if __name__ =3D=3D "__main__": > map =3D Map("thismap") > rule =3D Rule(1) > map.rules[rule.number] =3D rule > > > > with the above: > $ python -i inherit.py > >>> map > <__main__.Map object at 0xb7e889ec> > >>> map.rules > {1: Map rule number 1} > >>> map.rules[1] > Map rule number 1 > >>> > > > I have tried adding: > map.rules[2] =3D Rule(2) > > but that still gets: > > $ python -i inherit.py > >>> map.rules > {1: Map rule number 1, 2: Map rule number 2} > >>> > > and: > map.rule =3D Rule(3) > > which also doesn't really get me what I'm looking for: > > >>> map.rules > {1: Map rule number 1, 2: Map rule number 2} > >>> map.rule > Map rule number 3 > >>> > > > It seems to me what I'm trying to do is link an arbitrary child instance t= o an arbitrary instance of a > parent class, which in this case would be handy Because I'd like to popul= ate a map with rules and > print the rules including the parent map name for each rule. I'm just not= sure how I would go about > doing this in python. > > Any thoughts are welcome, and thanks in advance I not sure what you mean by the above. Can you provide an example of what yo= u want to occur and the output for it? ~Ramit This email is confidential and subject to important disclaimers and conditio= ns 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/disclo= sures/email.