Site icon Meccanismo Complesso

How to get all the functions in a Python module

How to get all the functions in a Python module m
How to get all the functions in a Python Module

Introduction

Sometimes you work with a Python module and does not have good documentation about it (or do not have it at all). In this short How To, you’ll see how to get the most information possible from a Python module, as the list of features or attributes eg.

Get the list of the functions and attributes of a Python module

First, you need to import the module

import nomemodulo

Then, you can use the dir() function to get a complete list of attributes and functions of a Python module

dir(nomemodulo)

It returns a list of all the functions and attributes of the module.

Also if you want to get specific information for each of these functions, you can use the help() function.

help(nomemodulo)

Example

import seolib

dir(seolib)

Here is the list with all functions

['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__title__', '__version__', 
'api', 'decorators', 'errors', 'get_alexa', 'get_facebook_likes', 'get_google_plus', 'get_semrush',
 'get_seomoz_data', 'get_tweets', 'helpers']

Finally if you want to know more detailed information, for example, about get_facebook_likes() function.

help(seolib.get_facebook_likes())
Help on function wrapper in module seolib.decorators:

wrapper(url, *args, **kwargs)

Further details

Among the functions and attributes found in the example above list there are some attributes worth mentioning. In fact there are a number of attributes that are generated by Python automatically when you create a new form. These attributes can be useful to obtain more information.

__builtins__ 

This attribute contains all attributes built-in that are accessible by the module.

__cached__

This attribute gives you the name and location of the cached files associated with the module. The path is relative to the current directory of Python.

__file__

This attribute gives you the name and location of the form file. The path is relative to the current directory of Python

__doc__

This attribute displays the module information, always assuming that the developer has ever entered them.

__initializing__

It determines whether the module is in the initialization phase. Generally, this value is always False, however, is useful in scripting when you want to ensure that a module has been fully imported (and initialized) before making any other particular operation (import a module that depends on it)

__loader__

This attribute shows the loader information for this module. The loader takes care of the just loaded module and puts it in memory so that Python can use it.

__name__ 

It contains the module name

__package__

This attribute is used by the system to load and manage internally the module[:]



Exit mobile version