发现python比java更容易出现循环依赖的问题
manager模块里定义了一个方法入口比如 get_by_tag(),通过search来实现,但search需要依赖models获取一些信息,这就产生了一个循环以来,可以通过两端代码来测试:
a.py
from b import getb print '------init a-------' def hello(): print getb()
b.py
from a import hello print '------init b-------' def getb(): return "i am b" def my_hello(): hello()
执行a.py 会报错:ImportError: cannot import name getb
解决办法,修改a.py,把
from b import getb
移到 hello()里。