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


Groups > comp.lang.python > #12785

Re: Need help with simple OOP Python question

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'else:': 0.03; 'instance': 0.05; 'subject:Python': 0.06; 'received:verizon.net': 0.07; 'terry': 0.07; '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; 'am,': 0.12; 'def': 0.15; '9:15': 0.16; '__init__': 0.16; 'declaration': 0.16; 'hierarchy': 0.16; 'reedy': 0.16; 'subject:OOP': 0.16; 'useless.': 0.16; 'wrote:': 0.16; 'subject:question': 0.18; 'jan': 0.19; 'trying': 0.21; 'holds': 0.21; 'subject:help': 0.22; 'header:In- Reply-To:1': 0.22; 'indexing': 0.23; 'code': 0.25; "i'm": 0.27; 'problem': 0.28; 'everyone,': 0.29; 'looks': 0.29; 'thanks': 0.30; 'class': 0.30; 'moving': 0.31; 'list': 0.32; 'objects': 0.32; 'usually': 0.32; 'to:addr:python-list': 0.33; 'header:User- Agent:1': 0.34; 'skip:- 40': 0.35; 'header:X-Complaints-To:1': 0.35; 'rather': 0.35; 'using': 0.37; 'received:org': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'sets': 0.39; 'header:Mime- Version:1': 0.39; 'subject:with': 0.39; "there's": 0.39; 'to:addr:python.org': 0.39; 'dict()': 0.84; 'trick.': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Need help with simple OOP Python question
Date Mon, 05 Sep 2011 13:38:08 -0400
References <dce02da0-c9c9-4331-aa2e-7d99f5e26cd1@g9g2000yqb.googlegroups.com> <87sjobo3es.fsf@benfinney.id.au> <93d65d9e-8a15-4423-94c0-3d385def24ed@et6g2000vbb.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding quoted-printable
X-Gmane-NNTP-Posting-Host pool-74-109-121-73.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20110812 Thunderbird/6.0
In-Reply-To <93d65d9e-8a15-4423-94c0-3d385def24ed@et6g2000vbb.googlegroups.com>
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.779.1315244354.27778.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1315244354 news.xs4all.nl 2537 [2001:888:2000:d::a6]:36305
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:12785

Show key headers only | View raw


On 9/5/2011 9:15 AM, Kristofer Tengström wrote:
> Thanks everyone, moving the declaration to the class's __init__ method
> did the trick. Now there's just one little problem left. I'm trying to
> create a list that holds the parents for each instance in the
> hierarchy. This is what my code looks like now:
>
> -----------------------------------------
>
> class A:
>      def __init__(self, parents=None):
>          self.sub = dict()
>          if parents:
>              self.parents = parents
>          else:
>              self.parents = []
>      def sub_add(self, cls):
>          hierarchy = self.parents
>          hierarchy.append(self)
>          obj = cls(hierarchy)
>          self.sub[obj.id] = obj

Indexing objects by their internal id is usually useless. Considier 
whether you should be using sets rather than dicts.

-- 
Terry Jan Reedy

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


Thread

Need help with simple OOP Python question Kristofer Tengström <krille012@gmail.com> - 2011-09-04 23:47 -0700
  Re: Need help with simple OOP Python question Stephen Hansen <me+list/python@ixokai.io> - 2011-09-05 00:07 -0700
  Re: Need help with simple OOP Python question Peter Otten <__peter__@web.de> - 2011-09-05 09:10 +0200
  Re: Need help with simple OOP Python question Ben Finney <ben+python@benfinney.id.au> - 2011-09-05 17:26 +1000
    Re: Need help with simple OOP Python question Kristofer Tengström <krille012@gmail.com> - 2011-09-05 06:15 -0700
      Re: Need help with simple OOP Python question Peter Otten <__peter__@web.de> - 2011-09-05 16:43 +0200
        Re: Need help with simple OOP Python question Jon Clements <joncle@googlemail.com> - 2011-09-05 07:59 -0700
          Re: Need help with simple OOP Python question Peter Otten <__peter__@web.de> - 2011-09-05 17:28 +0200
      Re: Need help with simple OOP Python question Terry Reedy <tjreedy@udel.edu> - 2011-09-05 13:38 -0400
        Re: Need help with simple OOP Python question Piet van Oostrum <piet@vanoostrum.org> - 2011-09-08 12:53 +0200

csiph-web