Home     My Faqts     Contributors     About     Help    

faqts : Computers : Programming : Languages : Python

FAQTs repaired & updated!
Thanks for your patience...
Entry Add Entry Alert - Edit this Entry

Did You Find This Entry Useful?

2 of 3 people (67%) answered Yes
Recently 2 of 3 people (67%) 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 17: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():
        do_something_with(parser_object)



© 1999-2004 Synop Pty Ltd