My Python version is 3.5.
I have a project with structure like this:
-- test
---- __init__.py
---- one
------ __init__.py
------ first.py
---- two
------ __init__.py
------ second.py
Content of first.py
file:
class FirstClass(object):
def hello(self):
return 'hello'
Content of second.py
file:
def main():
first = FirstClass()
print(first.hello())
if __name__ == '__main__':
main()
The problem is that I can't import FirstClass
in second.py
, I tried:
from test.one.first import FirstClass
Result:
Traceback (most recent call last):
File "second.py", line 3, in <module>
from test.one.first import FirstClass
ModuleNotFoundError: No module named 'test.one'
Also, I tried this approach:
from ..one.first import FirstClass
Result:
Traceback (most recent call last):
File "second.py", line 3, in <module>
from ..one.first import FirstClass
ValueError: attempted relative import beyond top-level package
So, my question is: how do to import in situations like this?