I have a module structured as follows:
/module __init__.py /submod_1 __init__.py submod_1_class.py /submod_2 __init__.py submod_2_class.py but I find it incredibly annoying to have to import a class within submod_1_class.py with:
from module.submod_1.submod_1_class import my_class What I would prefer to be able to type is:
from module import my_class I have browsed through the site-packages folder and looked through popular modules like numpy, but I haven't been able to figure out how, for example:
import numpy a = numpy.array([1,2,3,4,5]) can be used when the definition of numpy array objects is buried deep within several subfolders of the numpy package.
__init__.pyfiles to define what should be accessible from each module. For example, if you have one in/modulethat includesfrom submod_1.submod_1_class import class, then from outside the module you canfrom module import class. To stick withnumpy, for example, this line means that everything defined in this file can be imported straight fromnumpy.