Search code examples
python-3.xpycharmcode-completion

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?


Solution

  • 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