Python packages - import by class, not file

前端 未结 1 1476
悲哀的现实
悲哀的现实 2021-01-30 02:05

Say I have the following file structure:

app/
  app.py
  controllers/
    __init__.py
    project.py
    plugin.py

If app/controllers/project.p

相关标签:
1条回答
  • 2021-01-30 03:06

    You need to put

    from project import Project
    

    in controllers/__init__.py.

    Note that when Absolute imports become the default (Python 2.7?), you will want to add a dot before the module name (to avoid collisions with a top-level model named project), i.e.,

    from .project import Project
    
    0 讨论(0)
提交回复
热议问题