Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make PyCharm recognize string as path

I am working with Python 3.4.

When I use IDLE and start typing, e.g.,

my_main_folder = "C:/Us"

in the editor window, and then press Ctrl + Space, IDLE offers me all subfolders of C:, and if I press Tab, the string is completed to "C:/Users".

That means that IDLE (or Python Shell) is able to recognize a string as a path.

How to make PyCharm (Community edition) do that?

like image 251
Antoine Avatar asked Feb 20 '17 15:02

Antoine


2 Answers

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?

BUT,There is a work around for it in Community Edition.

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.

  • NOTE 1: this option may not be available if string is empty or has less than 2 characters in it
  • NOTE 2: this is temp injection -- AFAIK it will be lost after IDE restart (and you will need to do it again if needed)

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

like image 154
Ajay Singh Avatar answered Oct 14 '22 23:10

Ajay Singh


After searching I found this answer:

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

However, you can use CNTRL-SPACE twice and it will present a list of paths and files, example:

enter image description here

For a detailed description of this information see here

like image 21
13aal Avatar answered Oct 14 '22 23:10

13aal