Simple trick to work with relative paths in Python

Calculate the file path at runtime with ease

Mike Huls
Towards Data Science
5 min readOct 25, 2021

--

Let’s calculate the path to our target file (image by Tobias Rademacher on Unsplash)

The goal of this article is to calculate a path to a file in a folder in your project. The reason we calculate this path is that you refer to the correct location no matter where the code is installed. This is the case when you share your code with a coworker or deploy your code on a webserver e.g.

--

--