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


Groups > comp.lang.python > #100172

Re: Accessing container's methods

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Vincent Vande Vyvre <vincent.vande.vyvre@telenet.be>
Newsgroups comp.lang.python
Subject Re: Accessing container's methods
Date Tue, 8 Dec 2015 20:54:25 +0100
Lines 41
Message-ID <mailman.75.1449604867.12405.python-list@python.org> (permalink)
References <dcm0c2Fi2ktU1@mid.individual.net> <mailman.41.1449532084.12405.python-list@python.org> <5516674.oipO6xLiNU@PointedEars.de>
Reply-To vincent.vandevyvre@oqapy.eu
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de Q5owmy/f/TIUp8cZRv3GVAGZOD4CzQqsSIHg7zUOZaOQ==
Return-Path <vincent.vande.vyvre@telenet.be>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; '(self,': 0.07; 'nameerror:': 0.09; 'def': 0.13; '"key"': 0.16; 'class;': 0.16; 'containers': 0.16; 'contrived': 0.16; 'erik': 0.16; 'fix,': 0.16; 'from:name:vincent vande vyvre': 0.16; 'parent):': 0.16; 'parent:': 0.16; 'received:195.130': 0.16; 'received:195.130.137': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'received :telenet-ops.be': 0.16; 'subject:Accessing': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'issue.': 0.20; '"",': 0.22; 'defined': 0.23; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'van': 0.26; "skip:' 10": 0.28; 'container': 0.29; 'objects': 0.29; "i'm": 0.30; 'code': 0.30; 'received:be': 0.30; 'post': 0.31; "can't": 0.32; 'class': 0.33; 'traceback': 0.33; 'file': 0.34; 'should': 0.36; 'alone': 0.36; 'child': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'setting': 0.37; 'test': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'your': 0.60; 'thomas': 0.63; 'different': 0.63; 'here': 0.66; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; '.....': 0.76; '"index"': 0.84; '(let': 0.84; 'container).': 0.84; 'amongst': 0.91
User-Agent Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.4.0
In-Reply-To <5516674.oipO6xLiNU@PointedEars.de>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:100172

Show key headers only | View raw


Le 08/12/2015 20:02, Thomas 'PointedEars' Lahn a écrit :
> Erik wrote:
> ^^^^
> Please fix, Erik #75656.
>
>> On 07/12/15 18:10, Tony van der Hoff wrote:
>>> A highly contrived example, where I'm setting up an outer class in a
>>> Has-a relationship, containing a number of Actors. The inner class needs
>>> to access a method of the outer class; here the method get_name.
>> Generally, an object should not need to know which container it's in
> NAK.  All kinds of objects already "know" which container they are in.
>
>> (let alone its "index" or "key" in that container).
> That is a different issue.
>
>> Amongst other things, you can't put the object into multiple containers
> You can.  Quickhack:
>
> class Child:
>      self._parents = []
>
>      def add_to_parent (self, parent):
>          self._parents.append(parent)
>          self._parents = list(set(self._parents))
>
>      def get_parents (self)
>          return self._parents
>
> class Parent:
>      self._children = []
> .....
I thing you should test your code before post it.

 >>> class Child:
...     self.parents = []
...
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "<stdin>", line 2, in Child
NameError: name 'self' is not defined

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


Thread

Accessing container's methods Tony van der Hoff <tony@vanderhoff.org> - 2015-12-07 18:10 +0000
  Re: Accessing container's methods Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2015-12-07 18:21 +0000
  Re: Accessing container's methods Michael Torrie <torriem@gmail.com> - 2015-12-07 11:36 -0700
    Re: Accessing container's methods Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-12-07 20:03 +0100
  Re: Accessing container's methods Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-12-07 19:46 +0100
  Re: Accessing container's methods Peter Otten <__peter__@web.de> - 2015-12-07 19:59 +0100
  Re: Accessing container's methods Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-07 12:33 -0700
  Re: Accessing container's methods Terry Reedy <tjreedy@udel.edu> - 2015-12-07 16:38 -0500
  Re: Accessing container's methods Chris Angelico <rosuav@gmail.com> - 2015-12-08 09:02 +1100
  Re: Accessing container's methods Erik <python@lucidity.plus.com> - 2015-12-07 23:47 +0000
    Re: Accessing container's methods Tony van der Hoff <tony@vanderhoff.org> - 2015-12-08 12:35 +0000
    Re: Accessing container's methods [solved] Tony van der Hoff <tony@vanderhoff.org> - 2015-12-08 13:46 +0000
    Re: Accessing container's methods Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-12-08 20:02 +0100
      Re: Accessing container's methods Vincent Vande Vyvre <vincent.vande.vyvre@telenet.be> - 2015-12-08 20:54 +0100
        Re: Accessing container's methods Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-12-08 23:51 +0100
      Re: Accessing container's methods Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-08 20:30 +0000
        Re: Accessing container's methods Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-12-08 23:52 +0100
          Re: Accessing container's methods Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-08 22:59 +0000
      Re: Accessing container's methods Erik <python@lucidity.plus.com> - 2015-12-08 22:37 +0000
      Re: Accessing container's methods Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-08 16:41 -0700
      Re: Accessing container's methods Chris Angelico <rosuav@gmail.com> - 2015-12-09 12:04 +1100

csiph-web