Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!txtfeed1.tudelft.nl!tudelft.nl!txtfeed2.tudelft.nl!amsnews11.chello.com!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'attributes': 0.05; 'attribute': 0.07; 'infinite': 0.07; '(it': 0.09; 'invokes': 0.09; 'loop.': 0.09; 'am,': 0.12; 'def': 0.13; '16,': 0.15; 'tries': 0.15; '@property': 0.16; 'attribute,': 0.16; 'crashes': 0.16; 'numpy': 0.16; 'cc:addr:python-list': 0.16; 'received:74.125.82.44': 0.16; 'received:mail-ww0-f44.google.com': 0.16; 'wrote:': 0.18; 'endless': 0.18; 'idea?': 0.18; 'cc:no real name:2**0': 0.20; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.24; 'stack': 0.24; 'function': 0.27; 'message- id:@mail.gmail.com': 0.28; 'generic': 0.29; 'cc:addr:python.org': 0.29; 'class': 0.29; 'instead': 0.33; 'named': 0.33; 'fri,': 0.34; 'received:74.125.82': 0.35; 'skip:" 10': 0.37; 'received:74.125': 0.37; 'received:google.com': 0.37; 'replace': 0.38; 'some': 0.38; 'more': 0.61; 'type': 0.61; '2011': 0.61; 'kind': 0.61; 'happen': 0.61; 'property': 0.63; 'otten': 0.84; 'recursion.': 0.84; 'subject:Class': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=5BKKqdMG+MfKYbcHHJ9bIHrnZpLrbXxAhcuEarjWfvw=; b=udZ2yoBevQJwb61yEnbjrpzNIF+eEWreMXUgZV/GfNIUW/RDybikLJwb4Vs8uisYpu 7AhhMiTF5dMBRbOt9+MFleRRwB3T3NShBWui6ujmCDcRN2FxTLrAXHJgy1EwE8L+gFqS VG+oHBiY2A3q5ouyFG86y6XPHS2+6rvQSGWqM= MIME-Version: 1.0 In-Reply-To: References: <4eeb0949$0$29979$c3e8da3$5496439d@news.astraweb.com> <3fe1021b-75ae-4e3d-a5b0-175ad00aefa4@i6g2000vbh.googlegroups.com> <08b0a976-dd2a-4728-b865-4d04f4e5b7fb@n10g2000vbg.googlegroups.com> From: Ian Kelly Date: Fri, 16 Dec 2011 09:23:47 -0700 Subject: Re: Class: @property -> .__dict__ To: Peter Otten <__peter__@web.de> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324052667 news.xs4all.nl 6880 [2001:888:2000:d::a6]:36777 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17361 On Fri, Dec 16, 2011 at 2:32 AM, Peter Otten <__peter__@web.de> wrote: > Ulrich wrote: > >> if I replace it to >> def attributelist(self): >> =A0 =A0 =A0 =A0 =A0# find all attributes to the class that are of type n= umpy >> arrays: >> =A0 =A0 =A0 =A0 =A0return [attr for attr in dir(self) if >> isinstance(getattr(self, attr), numpy.ndarray)] >> >> it crashes going into some kind of endless loop. >> >> Do you happen to have any idea? > > dir(self) finds an attribute named "attributelist", getattr(self, > "attributelist") then tries to calculate the value of that attribute, > invokes dir(self) which finds an attribute named "attributelist" and so o= n > ad infinitum or the stack overflows. Try (untested) > > @property > def attributelist(self): > =A0 =A0return [attr for attr in dir(self) if attr !=3D "attributelist" an= d > =A0 =A0 =A0 =A0 =A0 =A0isinstance(getattr(self, attr), numpy.ndarray)] > > to avoid the infinite recursion. Or remove attributelist from the class (it feels more like a generic function than a class property to me) or make it a method instead of a property.