Enumerating Classes in Modules
Nick Coghlan
ncoghlan at email.com
Sat Nov 20 12:51:33 EST 2004
Rob Snyder wrote:
> Just in case anyone "follows in my footsteps" and has the same problem I did
> - Jeff's answer is pretty much dead on. The only stumbling block I had was
> that the dir() returns a list of strings representating the name of the
> attributes, and includes things that are not class definitions (e.g.
> '--builtins--'). So two modifications are necessary:
>
> 1 - use the getattr() function with each item returned by dir() to actually
> load the class object
> 2 - use type() to determine if it really it really is a classobj
I would suggest "hasattr" with the method you're interested in as a better way
to perform step 2. That should cover both old and new style classes quite happily.
Cheers,
Nick.
More information about the Python-list
mailing list