photon
4/26/2014 - 6:01 AM

python import from package

anypackage/
    __init__.py
    xxx.py     # class WWW is originally defined in this xxx file.

generally speaking, python can only import class from modules, which is usually a .py file.

import WWW from xxx

But, we can also import class from a package(folder) directly, rather than from the module. This is where an __init__.py file can step onto the stage.

anypackage/
    __init__.py  # class WWW is then moved here.
    xxx.py   

After we move the class from ordinary python file xxx.py to special python file __init__.py, we can import it from "anypackage" directly:

import WWW from anypackage

Why do we need to import from package, if we can import from module? 
When we import from a package, it can probably be viewed as a shortcut, as soft link in linux system

http://stackoverflow.com/questions/582723/how-to-import-classes-defined-in-init-py