Python Modules and Packages

Example

To create a package foo that contains a module bar and function hello.

from foo.bar import hello

hello()

Directory named foo contains empty file named init.py and file named bar.py. The file contains the function hello.

General scheme

from <package>.<sub package>.<module> import <function/class>

The init.py could contain the following import statement.

from <package>.<module> import <function/class>

Which would allow the module to be imported into other modules with the following import statement that imports directly from the package and not the module.

from <package> import <function/class>