Functions in Python Module

0 bob s · August 24, 2015
Is there anyway to tell what functions are included in a module? Is there a command or something we can type after we import a module?

Post a Reply


Oldest  Newest  Rating
0 Halcyon Abraham Ramirez · August 24, 2015
check this link out:

you use the inspect module

basically like this

import your_module
import inspect

functions_in_module = inspect.getmembers(your_module,inspect.isfunction)
0 Robin Cox · August 25, 2015
You could also just open the python module in a python IDE and check the code yourself :)
0 Vadim Kotlarov · August 26, 2015
There is also a function called "dir" that returns a list of all the functions and variables in a specific module.
import os

print(dir(os)) # The output will show a list of all functions and variables in the module.
0 bob s · August 26, 2015
Thanks guys, but I found an easier way to do this.

All you need to do is type:
for example:

import math
dir(math) RETURNS:

['__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']
  • 1



This section is all about snakes! Just kidding.

Bucky Roberts Administrator