How to make an “always relative to current module” file path?

The solution is to use __file__ and it’s pretty clean:

import os

TEST_FILENAME = os.path.join(os.path.dirname(__file__), 'test.txt')

Leave a Comment