Python circular import

I have a problem with a circular problem:

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 

I followed this guy's recommendation to deal with circular imports, only by importing the module: https://stackoverflow.com/a/2208778

But I still have a mistake. Now what?

UPDATED

OK, I solved the problem by running in account / model_managers.py:

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

Although it looks bulky. Not sure if this is pythonic ...

+1
python import circular-dependency
Aug 18 '13 at 6:49
source share

No one has answered this question yet.

See similar questions:

41
python circular import again (aka wrong with this design)
3
What is the difference between "import pkg.a as a" and "from pkg import a"?

or similar:

5504
Does Python have a ternary conditional operator?
5231
What are metaclasses in Python?
4473
Calling an external command in Python
3790
How can I safely create a subdirectory?
3602
Does Python have a "contains" substring method?
3119
What is the difference between Python list methods that are added and expanded?
2818
Finding an index of an element with a list containing it in Python
2568
How to find out the current time in Python
1762
How to import SQL file using command line in MySQL?
36
How to import a module in Python using importlib.import_module



All Articles