The path of the executable file can be obtained with
__file__, so use ʻos.path.dirname
to make it a directory. Use ʻos.path.join to connect the path to the file you want.
. └── some_dir ├── products.json └── test.py
import os dirname = os.path.dirname(__file__) filename = os.path.join(dirname, 'products.json') with open(filename) as f print(f.read())