Modules and packages in Python
Todo: common issues with setting up a Python project, system paths, missing imports, environment mismatches...
Module
an object of ModuleType type
example: the Python built-in math module
from Python console, type `import math`
globals()[‘math’] shows you details of this module
similarly, math.__dict__ includes important variables:
__name__ : name of the module
__file__: location of the module.
For built-in libraries such as math, this points to some Python C binary: math.__dict__["__file__"]
'/Users/foo/anaconda/lib/python3.6/lib-dynload/math.cpython-36m-darwin.so'
For standard libraries, such as re (for regex utilities), this points to a Python script
re.__dict__["__file__"]
'/Users/foo/anaconda/lib/python3.6/re.py'
globals()[‘say_hello’]
math_module = globals()[‘math’]
math_module.sqrt(9)
built in (in the language) vs standard libraries (.py)
imported modules are loaded into system cache
import sys
sys.modules: a dictionary in memory
second import of math module will look into sys.modules first, avoid loading existing modules multiple times
math.__dict__, fractions.__dict__
__name__
__file__: location of