What will happen if two modules import each other?
To generalize the problem, what about the cyclic imports in Python?
73
25
|
What will happen if two modules import each other? To generalize the problem, what about the cyclic imports in Python? | ||||||||||||||||||||
|
81
|
There was a really good discussion on this over at comp.lang.python last year. It answers your question pretty thoroughly.
| ||||||||
|
61
|
If you do " The problem is when instead you do " |
发现python比java更容易出现循环依赖的问题
manager模块里定义了一个方法入口比如 get_by_tag(),通过search来实现,但search需要依赖models获取一些信息,这就产生了一个循环以来,可以通过两端代码来测试:
a.py
b.py
执行a.py 会报错:ImportError: cannot import name getb
解决办法,修改a.py,把
移到 hello()里。