modules

Modules enables scripts to be used and included from other sources or your own without rewriting them each time.

Also each time python is restarted the global symbol table that keep all your variables is also restarted so the use of modules is fundamental to Python.

Note also each module has its own private symbol table.

A module is a file name module_name.py containing Python definitions and statements

.py files can be added by either using import filename or using from filename import *

Modules can import other modules (submodules can also be imported using filename.submodule)

Module Search Path

Python comes with a library of standard modules built in, the interpreter first searches for a built-in module , If not found, it then searches for a file in the current directory or in a list of directories given by the variable sys.path.

Modules as script

Python can also run a module provided it has been written with a return system value (normally used for testing only)

See also Packages

Link to Python.org