Python for Developers

First Edition

Chapter 10: Packages


Packages are folders that are identified by the interpreter by the presence of a file named __init__.py. Packages work as collections to organize modules hierarchically.

Package

You can import all package modules using the statement from packagename import *.

The __init__.py file can be empty or contain package initialization code or define a variable called __all__, a list of modules of the package that will be imported when using "*". Without the file, Python does not recognize the folder as a valid packet.

In [1]:
 
Out[1]: