0👍
✅
Putting imports at the end of your a.py and b.py should fix issues.
If it doesn’t help you try to move import into class definition block, so replace
from .a import TestA
Class TestB(object):
pass
to
Class TestB(object):
from .a import TestA
pass
Small Suggestion: do not use relative imports.
1👍
There’re several approaches you can use to address the cross-imports problem:
-
Re-organize your modules so that there’re no cross-imports, i.e. put the classes to a single module, etc.
-
Replace
from module import foo
withimport module
and use full names. -
Put imports at the end of modules (not recommended).
See also Circular imports in Python.
- How to create new horizontal row for each field in django form?
- Building JSON object that can hold contents of file
Source:stackexchange.com