python - Import module from sibling package with absolute import -
how 1 use absolute imports module of sibling package?
package file structure:
. ├── │ ├── __init__.py │ └── modulea.py ├── b │ ├── __init__.py │ ├── moduleb.py ├── __init__.py └── test.py
files test.py , a/modulea.py:
from b.moduleb import f if __name__ == '__main__': f()
file b/moduleb.py:
def f(): print('hello')
this works:
% python test.py hello
this not:
% python a/modulea.py traceback (most recent call last): file "a/modulea.py", line 1, in <module> b.moduleb import f importerror: no module named 'b'
as far can tell documentation should work: http://docs.python.org/3.3/tutorial/modules.html#intra-package-references. missing something?
you need __init__.py
in whatever .
is.
Comments
Post a Comment