In Python, a directory becomes a package when it contains one or more Python modules. For example, placing first.py, second.py, and third.py in mypackage groups them for import. section 9.9
Use the directory structure to choose an import style:
- Import a module directly with from mypackage import first, then access attributes as first.x. section 9.9
- Import through the full package name with import mypackage.first, then use mypackage.first.x. section 9.9
- Add __init__.py when importing mypackage itself; Python loads and executes that file. section 9.9
A small package directory
mypackage/ __init__.py first.py second.py third.py With the directory available through sys.path, Python can locate mypackage.first and import its contents. section 9.9
from mypackage import first
Explore the direct module-import form for a package directory. section 9.9






