Python - Modules


A python module is a single python file. The module's name is the file name without the extension.

Packages

A package is a single python application that consists of modules and subpackages.

An __init__.py file is required in every directory and sub-directory where modules/sub-packages exist for a package. This file is generally empty but may contain code to initialize the package.

Pycache

The __pycache__ directory caches (saves) "compiled" python code. The timestamp of the python file is checked. If it's been updated, the cache is updated.

Search Path

Module search path:

  1. Current directory / script directory
  2. PYTHONPATH
  3. Default path, i.e. /user/local/lib/python/