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


Groups > comp.lang.python > #64700

Re: Class and instance related questions.

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'static': 0.04; 'attribute': 0.07; 'class,': 0.07; 'correct.': 0.07; 'attributes': 0.09; 'explanation': 0.09; 'friday,': 0.09; 'subject:instance': 0.09; 'subject:related': 0.09; "they've": 0.09; 'cc:addr:python- list': 0.11; 'jan': 0.12; '24,': 0.16; 'apology': 0.16; 'bounds': 0.16; 'footnote': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'garbage': 0.16; 'metaclass': 0.16; 'normal,': 0.16; 'op.': 0.16; 'retains': 0.16; 'unbind': 0.16; 'sat,': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'mechanism': 0.19; "python's": 0.19; 'example': 0.22; 'cc:addr:python.org': 0.22; 'question': 0.24; 'cc:2**0': 0.24; 'references': 0.26; 'suggested': 0.26; 'header :In-Reply-To:1': 0.27; 'chris': 0.29; '[1]': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '25,': 0.31; 'container': 0.31; 'yes.': 0.31; 'class': 0.32; 'another': 0.32; 'something': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'instances': 0.36; 'useful': 0.36; 'possible': 0.36; 'january': 0.37; 'las': 0.37; 'list': 0.37; 'track': 0.38; 'itself': 0.39; 'delete': 0.39; 'system.': 0.39; 'how': 0.40; 'experts': 0.60; 'simple': 0.61; "you'll": 0.62; 'more': 0.64; 'within': 0.65; 'here': 0.66; '"not': 0.84; 'disappear': 0.84; 'gone.': 0.84; 'itself?': 0.84; 'sorry.': 0.91; 'subject:Class': 0.91; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=nk4oSdHQwtAYEQ5YmFMbLhGEOBPi2f4t4rcK1t6wmLo=; b=BKxOqBpHvcQI/DVaHfV6+Hros0mvCVVbAtC2liyj+ehYeq7LoyQQ4LSmo68GvLh7HI GE4Y91UqSjevtUl79WqBv8jmKReaR2AMT6FiZDT2W3rsgTsR2OWcubTaL1xQFdbERlFI J4N2HZuXLLGhfpHDQzEQYA4oK9ieHR0pE1UFcT0MLZY4dorRTaKTSAE6m4fEsD1bmXFV 3RiM7fJFdm95j0ZrtuOHGBrwZ0GlhIhZyAK3aLFuWL5oF0ayx23JPGbhYZhAuRfKnb1L 7Tf2lUR+HjpeE0tkz6/iq6TgwX4a1UyMi8BH/3qrs8dFmfcgNxE6GTgHT2xNWDBGnJFH 3O6A==
MIME-Version 1.0
X-Received by 10.68.247.6 with SMTP id ya6mr16181162pbc.45.1390596330703; Fri, 24 Jan 2014 12:45:30 -0800 (PST)
In-Reply-To <2c8035fe-7514-4598-9497-c2f90f9291c2@googlegroups.com>
References <b781b5d3-5dc0-4a7e-9792-78aadf2d6ab4@googlegroups.com> <mailman.5949.1390581460.18130.python-list@python.org> <2c8035fe-7514-4598-9497-c2f90f9291c2@googlegroups.com>
Date Sat, 25 Jan 2014 07:45:30 +1100
Subject Re: Class and instance related questions.
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Newsgroups comp.lang.python
Message-ID <mailman.5952.1390596339.18130.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1390596340 news.xs4all.nl 2971 [2001:888:2000:d::a6]:36763
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64700

Show key headers only | View raw


On Sat, Jan 25, 2014 at 7:32 AM, Asaf Las <roegltd@gmail.com> wrote:
> On Friday, January 24, 2014 6:37:29 PM UTC+2, Chris Angelico wrote:
>> On Sat, Jan 25, 2014 at 3:31 AM, Asaf Las <r...@gmail.com> wrote:
>> > Hi
>> > Is there way to get list of instances of particular
>> > class through class itself? via metaclass or any other method?
>> Not automatically, but you can make a class that keeps track of its
>> instances with a weak reference system.
>
> By "not automatically" do you mean there is no way to get references to instances of class via python's provided methods or attributes for class
> object at time the class object is created?

Correct.

> And usage of weak reference was suggested only to allow class instances
> garbage collected if for example class static container attribute will be
> used as class instance reference storage?

Weak references mean that the objects will be disposed of as normal,
but that you'll know that they've gone.

>> > Another question - if class is object is it possible
>> > to delete it? If it is possible then how instances
>> > of that class will behave?
>>
>> It's possible to unbind the name, but every instance retains a
>> reference to its class, so the class itself won't disappear until
>> there are no instances left of it.
>>
>> ChrisA
>
> That is interesting. Is it also reference count mechanism or something else?

Yes. [1]

ChrisA

[1] Within the bounds of the question asked, I think a simple "Yes" is
more useful here than a long and detailed explanation of the many
Pythons and how not all of them refcount at all. Consider this
footnote my apology to the experts who would otherwise feel that I'm
majorly misleading the OP. Sorry.

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


Thread

Class and instance related questions. Asaf Las <roegltd@gmail.com> - 2014-01-24 08:31 -0800
  Re: Class and instance related questions. Chris Angelico <rosuav@gmail.com> - 2014-01-25 03:37 +1100
    Re: Class and instance related questions. Asaf Las <roegltd@gmail.com> - 2014-01-24 12:32 -0800
      Re: Class and instance related questions. Chris Angelico <rosuav@gmail.com> - 2014-01-25 07:45 +1100
        Re: Class and instance related questions. Asaf Las <roegltd@gmail.com> - 2014-01-24 13:03 -0800
          Re: Class and instance related questions. Chris Angelico <rosuav@gmail.com> - 2014-01-25 08:18 +1100
            Re: Class and instance related questions. Asaf Las <roegltd@gmail.com> - 2014-01-24 14:08 -0800
          Re: Class and instance related questions. Dave Angel <davea@davea.name> - 2014-01-24 18:58 -0500
      Re: Class and instance related questions. Terry Reedy <tjreedy@udel.edu> - 2014-01-24 20:08 -0500

csiph-web