I have a project structure like the one below:
└── core
├── lib
│ └── some.jar
└── src
└── main
└── main.py
Now I am trying to access the some.jar inside the main.py file. It works fine with the absolute path but when I try to do something like below, it fails.
file:///../../lib/some.jar
I also tried the below code:
os.path.join(os.path.dirname(os.path.realpath(__file__)), "lib")
but It gives the path as below:
/Users/IdeaProjects/getmesomeproject/core/src/main/lib
Is there anyway to pass the relative path of the JAR file?
>Solution :
You can use pathlib to get the parent path
from pathlib import Path
os.path.join(Path(os.path.dirname(os.path.realpath(__file__))).parent.parent, "lib")
This should give you
/Users/IdeaProjects/RankedMatchmaking/core/lib