pythonpython-3.xresourcesrelativesource

Get resource from python resource root


I am using the PyCharm IDE. I marked a folder as a resource root and wanted to get a file from its directory and was wondering the appropriate way to do so.

In Java, you can use getClass().getResource("/resourceName.extension")

Is there some way to get a path from a python in said manner?


Solution

  • What I want can be accomplished by this answer.

    I used the code as follows:

    os.path.join(os.path.dirname(__file__), '../audio/music.wav'