Remove python circular import
问题 user.py: from story import Story class User: ... def get_stories(self): story_ids = [select from database] return [Story.get_by_id(id) for id in story_ids] story.py from user import User class Story: ... def __init__(self, id, user_id, content): self.id = id self.user = User.get_by_id(user_id) self.content = content as you can see, there is a circular import in this program, which causes an ImportError . I learned that I can move the import statement in method definition to prevent this error