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


Groups > comp.lang.python > #64695

Re: Class and instance related questions.

References <b781b5d3-5dc0-4a7e-9792-78aadf2d6ab4@googlegroups.com>
Date 2014-01-25 03:37 +1100
Subject Re: Class and instance related questions.
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5949.1390581460.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Jan 25, 2014 at 3:31 AM, Asaf Las <roegltd@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.

> 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

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