Pycharm 汽车相对进口 [英] Pycharm auto relative imports

查看:69
本文介绍了Pycharm 汽车相对进口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当您使用 PyCharm 提供的自动导入时,它都会生成绝对路径导入.即

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

from my_package.my_subpackage import my_thing

代替

from .my_subpackage import my_thing

在导入python包时是否有使用相对导入而不是绝对导入的设置?

Is there a setting to use relative imports instead of absolute ones when importing a python package?

推荐答案

目前似乎没有方法可以将自动导入功能的导入样式更改为使用相对导入.您可以对 import 语句进行的唯一样式更改是绝对导入的结构:

It appears currently there is no way to change the import style for auto-import feature to use relative imports. The only style changes you can make to import statements are how the absolute imports are structured:

(顺便提一下,Jetbrains/PyCharm 设置搜索功能非常好).

(The Jetbrains/PyCharm settings search functionality is excellent by the way).

重构时也会发生同样的事情,这绝对是我希望添加的选项.

The same thing happens when refactoring, it's definitely an option I'd like to see added.

这篇关于Pycharm 汽车相对进口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆