Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'arguments': 0.07; 'class,': 0.07; 'constructor': 0.07; 'def': 0.10; 'passing': 0.15; 'to:name:python-list': 0.15; 'attributes,': 0.16; 'dependent.': 0.16; 'thanks,': 0.18; 'bit': 0.21; 'received:209.85.214.174': 0.21; 'this:': 0.23; 'message-id:@mail.gmail.com': 0.27; 'idea,': 0.29; 'obj': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; "i'm": 0.29; 'suggestion': 0.32; 'could': 0.32; 'to:addr:python-list': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'needed': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'skip:u 20': 0.36; 'but': 0.36; 'moment': 0.37; 'received:209': 0.37; 'object': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'situation': 0.62; 'andrea': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=wRmQwe1GOUtsjLYJ9S2Rko9mdsGBrEaWFnRQCHdSXRA=; b=F982jLdwKEJT6Udyv0aTIdM27DGN0aw/e0FLz77ySj9AiYc4EWlTyglD+TguonfyPE BR9TvwAkOqn1R2/CzgNon1SSdejgl/3ElNoeQaI5PsxyyIJGHdqKwnYpxBE2CeWUa4pt qQUjwgOHXA9+5NJo33TjE0Cm6KclrKNPdA+812Y5le0pIGKP/mNdvd2wU4wSb5C7XzN5 MQmgUUiCmnNm+1cun4XC8ZfXu01E1AHDFDl8QK7dshMP9/5XY5T9+OMEc89NRfuCEyps yY8O2XUh46RQ/TlOKPM5+Df1/Q6RFiIb2YuZw7837lqSUF1dSbiMSLEE1Aqy5Hgkcy60 hZJg== MIME-Version: 1.0 Date: Thu, 13 Sep 2012 13:51:17 +0100 Subject: main and dependent objects From: andrea crotti To: python-list 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347540680 news.xs4all.nl 6842 [2001:888:2000:d::a6]:43850 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29028 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