How to list all functions in an imported module?
Peter Hansen
peter at engcorp.com
Thu May 27 19:25:49 EDT 2004
Peter Abel wrote:
> klachemin at home.com (Kamilche) wrote in message news:<889cbba0.0405270506.3cd91d26 at posting.google.com>...
>
>>I can't figure out how to list all functions from an imported module.
>>I searched Google, but all the answers I found didn't work. Did
>>something change in Python 2.2, perhaps there's a new method of doing
>>it?
>
>
> e.g the module os
>
>
>>>>import os,types
>>>>for k,v in os.__dict__.items():
>
> ... if type(v) == types.BuiltinFunctionType or\
> ... type(v) == types.BuiltinMethodType or\
> ... type(v) == types.FunctionType or\
> ... type(v) == types.MethodType:
> ... print '%-20s: %r' % (k,type(v))
Yuck... wouldn't using "callable(v)" be a lot nicer?
-Peter
More information about the Python-list
mailing list