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')) 

see what __path__ useful for?


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -