Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17342

Re: Class: @property -> .__dict__

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'attributes': 0.05; 'attribute': 0.07; 'infinite': 0.07; 'invokes': 0.09; 'loop.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'def': 0.13; 'tries': 0.15; '@property': 0.16; 'attribute,': 0.16; 'crashes': 0.16; 'numpy': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'wrote:': 0.18; 'endless': 0.18; 'idea?': 0.18; 'from:addr:web.de': 0.23; 'stack': 0.24; 'class': 0.29; 'header:X-Complaints-To:1': 0.33; 'named': 0.33; 'to:addr :python-list': 0.34; 'skip:" 10': 0.37; 'replace': 0.38; 'received:org': 0.38; 'some': 0.38; 'to:addr:python.org': 0.40; 'type': 0.61; 'kind': 0.61; 'happen': 0.61; 'recursion.': 0.84; 'subject:Class': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Class: @property -> .__dict__
Date Fri, 16 Dec 2011 10:32:45 +0100
Organization None
References <ad04c206-dbfd-4e49-b365-943b47844c41@n6g2000vbg.googlegroups.com> <4eeb0949$0$29979$c3e8da3$5496439d@news.astraweb.com> <3fe1021b-75ae-4e3d-a5b0-175ad00aefa4@i6g2000vbh.googlegroups.com> <08b0a976-dd2a-4728-b865-4d04f4e5b7fb@n10g2000vbg.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084b384.dip.t-dialin.net
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.3719.1324027975.27778.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1324027975 news.xs4all.nl 6888 [2001:888:2000:d::a6]:50933
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17342

Show key headers only | View raw


Ulrich wrote:

> if I replace it to
> def attributelist(self):
>          # find all attributes to the class that are of type numpy
> arrays:
>          return [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 on 
ad infinitum or the stack overflows. Try (untested)

@property
def attributelist(self):
    return [attr for attr in dir(self) if attr != "attributelist" and
            isinstance(getattr(self, attr), numpy.ndarray)]

to avoid the infinite recursion.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Class: @property -> .__dict__ Ulrich <ulrich@dorda.net> - 2011-12-16 00:52 -0800
  Re: Class: @property -> .__dict__ Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-16 09:03 +0000
    Re: Class: @property -> .__dict__ Ulrich <ulrich.dorda@gmail.com> - 2011-12-16 01:11 -0800
      Re: Class: @property -> .__dict__ Ulrich <ulrich.dorda@gmail.com> - 2011-12-16 01:14 -0800
        Re: Class: @property -> .__dict__ Peter Otten <__peter__@web.de> - 2011-12-16 10:32 +0100
        Re: Class: @property -> .__dict__ Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-16 09:23 -0700
  Re: Class: @property -> .__dict__ Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-12-16 11:02 +0100

csiph-web