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


Groups > comp.lang.python > #100176

Re: Accessing container's methods

Path csiph.com!au2pb.net!2.us.feeder.erje.net!feeder.erje.net!1.eu.feeder.erje.net!news.roellig-ltd.de!open-news-network.org!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.python
Subject Re: Accessing container's methods
Date Tue, 08 Dec 2015 23:51:10 +0100
Organization PointedEars Software (PES)
Lines 41
Message-ID <3619885.mg2BhAsQCr@PointedEars.de> (permalink)
References <dcm0c2Fi2ktU1@mid.individual.net> <mailman.41.1449532084.12405.python-list@python.org> <5516674.oipO6xLiNU@PointedEars.de> <mailman.75.1449604867.12405.python-list@python.org>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1449615071 25700 eJwFwQkRADAIAzBLcKNwyOGrfwlL8Fx9whxuINhaJr28yUCTg13yxVs9uduoy0stmjhm5QNMUBKx (8 Dec 2015 22:51:11 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Tue, 8 Dec 2015 22:51:11 +0000 (UTC)
User-Agent KNode/4.14.2
X-User-ID eJwNx8kBwCAIBMCW5NrFckSh/xKS+U0YBJeOgMfEqBQ5wQ22Ucv7voSx/oubLkWl+ihfS0Se2qddpGzRzfABMT0USg==
Cancel-Lock sha1:sf7KHCS33KtV/h9ZS+pwIXj5nWg=
X-NNTP-Posting-Host eJwFwQEBACAIA7BKoPxqHDnSP4IbJp1aQTDQ6MQFQt7wJL1SbZ3z7ndWK8pqYECP3HaC+iqHEWE=
Xref csiph.com comp.lang.python:100176

Show key headers only | View raw


Vincent Vande Vyvre wrote:

> Le 08/12/2015 20:02, Thomas 'PointedEars' Lahn a écrit :
>> Erik wrote:
>>> 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.

I _think_ you should read postings more carefully before replying to them.
 
>  >>> 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

Can be fixed easily by omitting “self.” there; likewise in Parent.  (In 
other programming languages I know, you need to refer to the class/instance 
explicitly to which you add attributes/properties.)

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

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