Can ask a class for its functions?

Troy Melhase troy at gci.net
Wed Aug 14 22:10:30 EDT 2002


Or more list-comprehension-ly?

        [x for x in clazz.__dict__.values() if callable(x)]


Peter Hansen wrote:

> Troy Melhase wrote:
>> 
>> This doesn't work because dir() returns a list of strings, none of which
>> are callable.
>> 
>> What you meant was:
>> 
>>         filter(callable, [getattr(class_, attr) for attr in dir(class_)])
> 
> Or more simply?
> 
>     filter(callable, clazz.__dict__.values())
> 
> -Peter

-- 
Troy Melhase
mailto:troy at gci.net
http://melhase.com/




More information about the Python-list mailing list