Import neighboring module in python

2019-09-17 20:29发布

问题:

I have the following folder structure to keep my unit testing files separate from the actual module they test.

proj/
  foo/
    __init__.py
    bar.py
  tests/
    test.py

How can I import module foo from test.py?

回答1:

This should work

from .. import foo


标签: python import