When or why to use relative imports in Python

后端 未结 1 696
孤城傲影
孤城傲影 2020-12-30 22:07

Is there any rules or guidelines concerning when to use relative imports in Python? I see them in use all the time like in the Flask web framework. When searching for this t

相关标签:
1条回答
  • 2020-12-30 22:49

    Check out PEP 328's section on relative imports

    The rationale seems to be as written:

    Several use cases were presented, the most important of which is being able to rearrange the structure of large packages without having to edit sub-packages. In addition, a module inside a package can't easily import itself without relative imports.

    0 讨论(0)
提交回复
热议问题