Import Error. Circular References

前端 未结 2 688
渐次进展
渐次进展 2020-12-10 20:05

I have a package like this

package/
    __init__.py
    subpackage1/
        __init__.py
        moduleA.py
        moduleB.py
        moduleC.py
        mod         


        
2条回答
  •  -上瘾入骨i
    2020-12-10 20:40

    This isn't to do with hierarchy, it's to do with circular references. You can't tell file A to import file B, and file B to import file A - since they depend on each other, the circle can't be resolved.

    Either restructure your files so that they don't need to import each other - remember Python is not Java, you can have more than one class in a file - or move one of the imports into a function so that it doesn't have to execute at import time.

提交回复
热议问题