Pycharm auto relative imports

前端 未结 3 1462
星月不相逢
星月不相逢 2021-01-07 20:26

Whenever you use autoimport provided by PyCharm it generates an absolute path import. i.e.

from my_package.my_subpackage import my_thing

in

3条回答
  •  星月不相逢
    2021-01-07 20:38

    I would advise against relative in general, you can refer to this question: https://softwareengineering.stackexchange.com/a/159505

    Also, you can check official pep8 specs https://www.python.org/dev/peps/pep-0008/

    Absolute imports are recommended, as they are usually more readable and tend to be better behaved (or at least give better error messages) if the import system is incorrectly configured (such as when a directory inside a package ends up on sys.path):

    From my personal experience it turns out that they sometimes poorly integrate with Pycharm IDE when there's more complex package layout breaking test running through Pycharm. I suppose there might be some issues in other tools too.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题