packages - Python subpackage in arbitrary folder. How to write the __init__.py? -
if have hierarchy
a |- __init__.py |-b |- __init__.py |- funcitons.py (which contains def my_function(): pass)
and have package a
installed, can following
from a.b import functions functions.my_function()
or
from a.b.functions import my_function my_function()
how accomplish same result if b encapsulated in several subfolders (which not packages)?
as suggested antti haapala, in python 2 __path__
for. following a/__init__.py
did job.
import os __path__.append( os.path.join(os.path.dirname(__file__), 'res/path'))
Comments
Post a Comment