任何人都可以向我解释为什么在运行程序时出现以下错误吗?
ImportError: cannot import name 'Adviser' from 'src.models.adviser'
我的文件夹的结构如下...
root
-- src
models
-- __init__.py
-- adviser.py
-- episode.py
-- set_up.py
我有一个设置脚本...
from src.models.adviser import Adviser
if __name__ == "__main__":
for adv in Adviser.all():
print(adv)
# src.models.adviser.py
from .base_model import BaseModel
from orator.orm import has_many
from .episode import Episode
class Adviser(BaseModel):
@has_many
def learners(self):
return Episode
最后...
# src.models.episode.py
from .base_model import BaseModel
from orator.orm import belongs_to
from .adviser import Adviser
class Episode(BaseModel):
@belongs_to
def adviser(self):
return Adviser
如果我从src.models.episode.py
中删除了import语句,那么脚本将运行。
我不明白什么并做错了什么?
答案 0 :(得分:1)