All names in the current module

Ian Clark iclark at mail.ewu.edu
Wed Aug 15 18:03:11 EDT 2007


Ian Clark wrote:
> Torsten Bronger wrote:
>> Hallöchen!
>>
>> How can I get a list with all classes defined in the current module?
>> Thank you!
>>
>> Tschö,
>> Torsten.
>>
> 
> Assuming you want to see all classes in the re module:
> 
>  >>> import re
>  >>> help(re) #best way
>  >>>
>  >>> def isclass(cls):
> ...     try:
> ...             return issubclass(cls, cls)
> ...     except TypeError:
> ...             pass
> ...     return False
> ...
>  >>> [cls for cls in dir(re) if isclass(getattr(re, cls))]
> ['Scanner', '_pattern_type', 'error']
> 
> Ian
> 

I love this list, I learn something new everyday. Didn't know about 
inspect.isclass(). Ignore this post and look at Lawrence's.

Ian




More information about the Python-list mailing list