让PyCharm将字符串识别为路径

Ant*_*ine 14 code-completion pycharm python-3.x

我正在使用Python 3.4.

当我使用IDLE并开始输入时,例如,

my_main_folder = "C:/Us"

在编辑器窗口中,然后按Ctrl + Space,IDLE为我提供了所有子文件夹C:,如果我按下Tab,字符串就完成了"C:/Users".

这意味着IDLE(或Python Shell)能够将字符串识别为路径.

如何让PyCharm(社区版)做到这一点?

Aja*_*ngh 8

它不能在Community Edition Pycharm中使用.但它可以在Professional Edition Pycharm中完成.我建议你转到专业版.

PyCharm有自动完成文件路径吗?

但是,社区版有一个解决方法.

Place caret in such place and press Alt+Enter -- see if you will have "Inject language or reference" option in appeared menu. If it's present -- use it and choose "File Reference" there.

  • 注1:如果字符串为空或者字符串少于2个,则此选项可能不可用
  • 注2:这是临时注入 - 在IDE重启后它将丢失(如果需要,你需要再次进行)

Otherwise: select desired file in Project View panel and use "Copy Reference" -- it will copy a file path relative to the project root -- you may only need to add leading "/"...

https://intellij-support.jetbrains.com/hc/en-us/community/posts/206574619-Autocompleting-relative-paths


13a*_*aal 5

搜索后我找到了这个答案:

can we tab through paths, in the same way you can in the terminal?

不,它不可能:(

I wrote a plugin for Komodo called AutoCode that allowed me to ALT+Click on files in the Project view, and it would automatically resolve the right path

您可以使用文件右键单击菜单中的"复制引用"将相对于项目根目录的文件路径复制到剪贴板.但遗憾的是,这一行动并未考虑资源根源

但是,您可以使用CNTRL-SPACE两次,它将显示路径和文件列表,例如:

在此输入图像描述

有关此信息的详细说明,请参见此处