Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'attribute': 0.05; 'bootstrap': 0.07; 'class,': 0.07; 'method,': 0.07; 'loop.': 0.09; 'name)': 0.09; 'name):': 0.09; 'looked': 0.10; 'def': 0.10; '(like': 0.15; 'passing': 0.15; '"set': 0.16; 'cyclic': 0.16; 'frame,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'height,': 0.16; 'width,': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'instance,': 0.17; 'feb': 0.19; 'trying': 0.21; '(you': 0.23; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; 'creating': 0.26; 'message-id:@mail.gmail.com': 0.27; 'skip:_ 10': 0.29; 'class': 0.29; 'problem': 0.33; 'to:addr :python-list': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'self': 0.34; 'doing': 0.35; 'pm,': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'think': 0.40; 'your': 0.60; 'matter': 0.61; 'kind': 0.61; 'more': 0.63; '2013': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=19DvZhjVlXvHKa8qazn7vlxb0Bf8NByqUmeGQ0+coe8=; b=JCPgeNa87LC4Rrq751l1XDZvAeKlqDbXBxfeCotIdFILg6uqG20x2GG259sS6/a3eu 07PELSu55wMF2r+pcf4phnT1+kzpthy1rZ7MHOQnEPvKmDtN6KpNmjy28pNE8V7dvDa+ HHMOOiIvJTN9O0+QeERkNtqXqxeWJqa16I/TSp7lPWDK10WuG64ZWmivU1sbyYMg7Hgv rNE8e3KwgWSANaXviXfO34eg8P4mLxnHSp/+naiuMKg+CtZ9L8dmhO3osHlC+J/l+MNH NxfRihFOJ2A6rL+kLmhjKB1hVovX1OlXO4tPKP5IL8jGE6QPtpcYd+Vw81PNdsM2da9y thOw== MIME-Version: 1.0 X-Received: by 10.220.219.77 with SMTP id ht13mr19811147vcb.66.1359941323711; Sun, 03 Feb 2013 17:28:43 -0800 (PST) In-Reply-To: <095a0432-f8a4-40b4-96ed-1588896fba66@googlegroups.com> References: <095a0432-f8a4-40b4-96ed-1588896fba66@googlegroups.com> Date: Mon, 4 Feb 2013 12:28:43 +1100 Subject: Re: __getattr__ Confusion From: Chris Angelico To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359941331 news.xs4all.nl 6882 [2001:888:2000:d::a6]:40405 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38113 On Mon, Feb 4, 2013 at 12:08 PM, Saul Spatz wrote: > class ScrolledCanvas(Frame): > def __init__(self, master, width, height, bg, cursor): > canv = self.canvas = Canvas(self, bg=bg, relief=SUNKEN) > > def __getattr__(self, name): > return getattr(self.canvas, name) Trying to get my head around what you're doing here. Why are you inheriting Frame, but passing all attribute queries through to the Canvas? Why not inherit Canvas? It looks to me like you're going to have some kind of bootstrap problem no matter how you do it. You're creating a cyclic reference (you pass self to Canvas), so one way or another, you need to start the loop. Dunder methods (like __getattr__) are looked up in the class, not the instance, so you can't simply set it in the way you describe. I think your best bet is going to be the "set up a stub, then fill in the details" method, which is more or less what you're doing (a stubby __nonzero__). ChrisA