faqts : Computers : Programming : Languages : Python

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 4 people (50%) answered Yes
Recently 2 of 4 people (50%) answered Yes


If i want to find out all the objects in a particular class like parser, how do i find it?

Aug 29th, 2002 00:04
Peter Funk, bert cazzato,

I believe you want to find all instances of a specific class.
you could add a simple registry to the class to accomplish this:
    class Parser:
        instance_registry = {}
        def __init__(self, ....):
            """This is the constructor method of class Parser"""
            self.instance_registry[id(self)] = self
            .... other init code ....
        def foo(self): 
Later you can retrieve a list of all parser instances:
    for parser_id, parser_object in Parser.instance_registry.items():