Search code examples
pythonpython-2.7pythonxy

Python 2.7 function imports


When I say import numpy as np, I can access all the modules and submodules in numpy from np. I do not have to say np.matrixlib.matrix. What is this feature called? How do I implement this in my package.


Solution

  • If one want's that submodules are available in the main module, they have to be imported in __init__.py.

    See for example numpy/__init__.py:

    from .matrixlib import *
    

    imports everything from numpy.matrixlib into numpy.