python模块交叉引用
最近在python遇到了这样一个需求,有两个类A和B,A的f方法要构造B类对象,而B的g方法要构造A类对象.经过试验.代码如下
A.py的内容为
class A:
def g(self):
from B import B
return B()
B.py的内容为
class B:
def f(self):
from A import A
return A()
测试代码test.py的内容为:
from A imp
原创
2020-08-30 11:19:33 ·
522 阅读 ·
0 评论