Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'arguments': 0.07; 'class,': 0.07; 'constructor': 0.07; 'cc:addr:python-list': 0.10; 'def': 0.10; 'passing': 0.15; 'attributes,': 0.16; 'dependent.': 0.16; 'imo.': 0.16; 'thanks,': 0.18; 'bit': 0.21; 'cc:2**0': 0.23; 'dependent': 0.23; 'this:': 0.23; 'seems': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; 'idea,': 0.29; 'obj': 0.29; 'url:mailman': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; "i'm": 0.29; 'url:python': 0.32; '-----': 0.32; 'suggestion': 0.32; 'could': 0.32; 'url:listinfo': 0.32; 'another': 0.33; 'needed': 0.35; 'similar': 0.35; 'something': 0.35; 'skip:u 20': 0.36; 'but': 0.36; 'url:org': 0.36; 'moment': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'nothing': 0.38; 'sure': 0.38; 'where': 0.40; 'url:mail': 0.40; 'received:194': 0.61; 'situation': 0.62; 'between': 0.63; 'here': 0.65; 'andrea': 0.84; 'shocking': 0.84 X-IronPort-AV: E=Sophos;i="4.80,417,1344204000"; d="scan'208";a="722681" X-Virus-Scanned: amavisd-new at zimbra.sequans.com Date: Thu, 13 Sep 2012 15:24:24 +0200 (CEST) From: Jean-Michel Pichavant To: andrea crotti In-Reply-To: Subject: Re: main and dependent objects MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Mailer: Zimbra 7.2.0_GA_2669 (ZimbraWebClient - GC7 (Linux)/7.2.0_GA_2669) Cc: python-list 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347542654 news.xs4all.nl 6939 [2001:888:2000:d::a6]:58218 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29032 ----- Original Message ----- > I am in a situation where I have a class Obj which contains many > attributes, and also contains logically another object of class > Dependent. > > This dependent_object, however, also needs to access many fields of > the > original class, so at the moment we did something like this: > > > class Dependent: > def __init__(self, orig): > self.orig = orig > > def using_other_attributes(self): > print("Using attr1", self.orig.attr1) > > > class Obj: > def __init__(self): > self.attr1 = "attr1" > self.attr2 = "attr2" > self.attr3 = "attr3" > > self.dependent_object = Dependent(self) > > > But I'm not so sure it's a good idea, it's a bit smelly.. > Any other suggestion about how to get a similar result? > > I could of course passing all the arguments needed to the constructor > of > Dependent, but it's a bit tedious.. > > > Thanks, > Andrea > -- > http://mail.python.org/mailman/listinfo/python-list > Nothing shocking right here imo. It looks like a classic parent-child implementation. However it seems the relation between Obj and Dependent are 1-to-1. Since Dependent need to access all Obj attributes, are you sure that Dependent and Obj are not actually the same class ? JM