all subclasses of x in module

Mark McEahern marklists at mceahern.com
Thu Jan 24 17:06:03 EST 2002


Jason Orendorff wrote:
> In Python 2.2, if BillableItemStrategy is a new-style class (that is,
> if it subclasses object), then it has a __subclasses__() method that
> returns a list of its immediate subclasses, whereever they are defined.

Thanks, that did the trick!

  class BillableItemStrategy(object):pass

and:

  def getStrategyFactory():
    dict = {}
    for cls in BillableItemStrategy.__subclasses__():
        dict[cls.__name__] = cls
    return dict

Cheers!

// mark




More information about the Python-list mailing list