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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -