使 PyCharm 将字符串识别为路径
Make PyCharm recognize string as path
我正在使用 Python 3.4.
当我使用 IDLE 并开始打字时,例如,
my_main_folder = "C:/Us"
在编辑器window,然后按Ctrl + Space
,IDLE给我提供了C:
的所有子文件夹,如果我按Tab
,字符串就完成了"C:/Users"
.
这意味着 IDLE(或 Python Shell)能够将字符串识别为路径。
如何让 PyCharm(社区版)做到这一点?
搜索后我找到了这个答案:
can we tab through paths, in the same way you can in the terminal?
No, it's not posible:(
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
You can use 'Copy reference' in file right-click menu to copy file path relative to project root to clipboard. But this action doesn't unfortunately take resource roots into account
但是,您可以使用 CNTRL-SPACE
两次,它会显示一个路径和文件列表,例如:
有关此信息的详细说明,请参阅 here
Its not able in Community Edition Pycharm. But it can be done in Professional Edition Pycharm. I would suggest you to move to Professional Edition.
Does PyCharm have autocomplete file path?
但是,在社区版中有一个解决方法。
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 "/"...
我正在使用 Python 3.4.
当我使用 IDLE 并开始打字时,例如,
my_main_folder = "C:/Us"
在编辑器window,然后按Ctrl + Space
,IDLE给我提供了C:
的所有子文件夹,如果我按Tab
,字符串就完成了"C:/Users"
.
这意味着 IDLE(或 Python Shell)能够将字符串识别为路径。
如何让 PyCharm(社区版)做到这一点?
搜索后我找到了这个答案:
can we tab through paths, in the same way you can in the terminal?
No, it's not posible:(
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
You can use 'Copy reference' in file right-click menu to copy file path relative to project root to clipboard. But this action doesn't unfortunately take resource roots into account
但是,您可以使用 CNTRL-SPACE
两次,它会显示一个路径和文件列表,例如:
有关此信息的详细说明,请参阅 here
Its not able in Community Edition Pycharm. But it can be done in Professional Edition Pycharm. I would suggest you to move to Professional Edition.
Does PyCharm have autocomplete file path?
但是,在社区版中有一个解决方法。
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 "/"...