How do I list all the functions in a Python module?

You can use dir (module) to get all the attributes / methods of a Python module. For example,

 & gt; & gt; & gt; import math & gt; & gt; & gt; dir (math) [`__doc__`,` __name__`, `__package__`,` acos`, `acosh`,` asin`, `asinh`,` atan`, `atan2`,` atanh`, `ceil`,` copysign`, `cos`,` cosh`, `degrees`,` e`, `erf`,` erfc`, `exp`,` expm1`, `fabs`,` factorial`, `floor`,` fmod` , `frexp`,` fsum`, `gamma`,` hypot`, `isinf`,` isnan`, `ldexp`,` lgamma`, `log`,` log10`, `log1p`,` modf`, ` pi`, `pow`,` radians`, `sin`,` sinh`, `sqrt`,` tan`, `tanh`,` trunc`] 

But here, as you can see, module attributes (__name__, __doc__, etc.) are also listed. You can create a simple function that filters them out using the isfunction predicate and getmembers (module, predicate) to get the members of the module. For example,

 & gt; & gt ; & gt; from inspect import getmembers, isfunction & gt; & gt; & gt; import helloworld & gt; & gt; & gt; print [o for o in getmembers (helloworld) if isfunction (o [1])] [`hello_world`] 

Note that this does not work for built-in modules, since the function type for these modules is not a function, but a built-in function.

< br>

Get Solution for free from DataCamp guru