Python中的循环依赖如何解决呢?

时间:2015-07-22 07:16:50

标签: python circular-dependency

这是我项目的结构:

MyProject
|
|---- package1
|       |
|       |---- classA needs classXYZ
|       |-----classB needs classXYZ
|       |-----classC
|
|-----package2
|       |
|       |-----classXYZ (path creator)
|
|-----package3
|       |
|       |-----classQ (subclass of classR)
|       |-----classR 
|
|-----package4
|       |
|       |-----classDB needs classXYZ

ClassQ需要classAclassBclassRclassDBclassXYZ,所以,在classQ我有:

    from package1 import classA
    from package1 import classB
    from package2 import classXYZ 
    from package3 import classR
    from package4 import classDB

然而,课程classAclassB都使用classXYZ,这导致classQ我收到错误:Import Error: no module named classR.(Q级)继承自R类。

问题是:如何解决这个问题? Q类是某种主类,它使用其他模块中可用的函数来构建一个有效的应用程序。任何帮助将不胜感激。

0 个答案:

没有答案