Python循环导入

时间:2013-08-18 06:49:02

标签: python import circular-dependency

我有一个循环导入问题:

 File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 96, in load_app
    models = import_module('.models', app_name)

 File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)

  File "/Users/......../account/models.py", line 11, in <module>
    from account import model_managers as model_mgrs

  File "/Users/......../account/model_managers.py", line 6, in <module>
    from account import models as account_models
ImportError: cannot import name models

我按照这个人的建议,只通过导入模块来处理循环导入:https://stackoverflow.com/a/3956038/1724763

但我仍然有错误。现在怎么办?

已更新

好的,我在account / model_managers.py中解决了这个问题:

import importlib
account_models = importlib.import_module('.models', 'account')

虽然它确实看起来很笨重。不确定它是否是pythonic ......

0 个答案:

没有答案