Python – Get path of root project structure

I’ve got a python project with a configuration file in the project root.
The configuration file needs to be accessed in a few different files throughout the project.

So it looks something like: <ROOT>/configuration.conf
<ROOT>/A/a.py, <ROOT>/A/B/b.py (when b,a.py access the configuration file).

What’s the best / easiest way to get the path to the project root and the configuration file without depending on which file inside the project I’m in? i.e without using ../../? It’s okay to assume that we know the project root’s name.

22 Answers
22

Leave a Comment