I have got 2 modules which tend to import each other because they will be using each other in classes. I found in this link which tells to use try/except
statement along with imports to deal with circular imports, but still I am getting KeyError
instead.
The name of module is brand.py
which contains the following code:
try:
from erp.common.models.productwithspecs import ProductWithSpec, ProductWithSpecSchema
except ImportError:
import sys
ProductWithSpec = sys.modules[__package__ + '.productwithspecs.ProductWithSpec']
but I get the below error:
File "/home/arsalan/python_practise/MY_WORK_FILES/React_works/React_Container_Mount/backend/erp/common/models/brand.py", line 13, in <module>
ProductWithSpec = sys.modules[__package__ + '.productwithspecs.ProductWithSpec']
KeyError: 'erp.common.models.productwithspecs.ProductWithSpec'` Can anybody point out the mistake