I have a solution with different folders and I wanted to create a common package for them to share reusable code. There are lot of examples for python packages
are there. None of them addresses separate folder scenario in a simple way.
My folder structure is :
Client/
__init__.py
--logic.py
Common/
__init__.py
-- Constants.py
Server/
__init__.py
-- Test.py
My Test.py
looks like this :
from Common import Constant
print(Constant.TEST_VALUE) #-- From common package
But the code not even passes the import
statements.
Exception has occurred: ModuleNotFoundError No module named 'Common'
If I try with relative path : from ..Common import Constant
Error:
Exception has occurred: ImportError attempted relative import with no known parent package
My purpose is to reuse the constant.py
file for both Cars
and Server
solution. There are examples for sys.path
which I am not sure if its a good practice. Also the code in Common will not be having complex codes to proceed with installing them.