Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52847
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'talks': 0.03; 'class,': 0.07; '22,': 0.09; 'instance.': 0.09; 'def': 0.12; 'belongs': 0.16; 'class:': 0.16; 'name)': 0.16; "name=''):": 0.16; 'rule.': 0.16; 'subject: \n ': 0.16; 'subject:access': 0.16; 'subject:post': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'thu,': 0.19; 'seems': 0.21; 'aug': 0.22; 'rules': 0.22; 'print': 0.22; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'names.': 0.31; 'subject:that': 0.31; 'class': 0.32; 'probably': 0.32; 'skip:_ 10': 0.34; 'subject:the': 0.34; "i'd": 0.34; 'something': 0.35; 'no,': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'subject:?': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'subject:Can': 0.60; 'tell': 0.60; 'first': 0.61; "you'll": 0.62; 'name': 0.63; 'skip:n 10': 0.64; 'map': 0.64; 'number):': 0.84; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=RFarIJ7glZDBd2oa8S4K0szdpM8Ni2pIBYclCdcU0aM=; b=swfWDUFQafoCR8BmDHBfuNm9JWvwovyI2doEUKrRlM4W6LZugNV4OXdxtABTAxehpX fiuTW5JcmAJq9iNhzLUlGSTgSY6GfWfnZPzIq4hO/wAQhn1gG3kp28fATKsHWvtJ3uKy TIRkm3JwCylbYIwXeXRvFGYM/kzuVRopEDoTLC0fJZxLFWli5zg1oVisIpX15LSPS0MR UAEKH3fHntindg5r/9Fu5tfKU/EJWIbK5Xs39Xm8ejwtxKNKPwp/egaLTdmc0Bpdqorw Uh4vCVdC83RUySlnfdsgFFkDf7W2HHGbUO3paly7/uTFHvlxnrhb63qCpMeW1s3Nt99I z5yw== |
| X-Received | by 10.66.233.37 with SMTP id tt5mr7586487pac.95.1377208797877; Thu, 22 Aug 2013 14:59:57 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <5B80DD153D7D744689F57F4FB69AF47418683AD8@SCACMX008.exchad.jpmchase.net> |
| References | <14d50efb-e88b-4259-960a-97ef58e345d8@googlegroups.com> <5B80DD153D7D744689F57F4FB69AF47418683AD8@SCACMX008.exchad.jpmchase.net> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Thu, 22 Aug 2013 15:59:17 -0600 |
| Subject | Re: Can a child access parent attributes if that child added post-hoc as an attribute to the parent? |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.143.1377208801.19984.python-list@python.org> (permalink) |
| Lines | 43 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1377208801 news.xs4all.nl 16010 [2001:888:2000:d::a6]:51218 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:52847 |
Show key headers only | View raw
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.
>> It seems to me what I'm trying to do is link an arbitrary child instance to an arbitrary instance of a
>> parent class, which in this case would be handy Because I'd like to populate 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.
You'll need to keep a reference to the Map on each Rule instance. So
instead of self.mapName you'll have self.map.mapName. Your Rule class
should probably look something like this:
class Rule(object):
def __init__(self, map, number):
self.map = map
self.number = number
And then when you construct it you'll need to tell it what map it belongs to:
rule = Rule(map, 1)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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