I created a Python package with a structure as follows:
pkg_dir
-mypkg
-folder1
-_init_.py
-do_calc_.py
-folder2
-_init_.py
-my.json
.
.
.
setup.py
Inside the folder1/do_calc.py, I need to read the my.json file from folder2 and use it in folder1/do_calc.py.
I am importing this mypkg into another Python script, and I am calling the do_calc function. However, the script is failing because inside mypkg, this read statement in folder1/do_calc.py:
with open('../folder2/my.json') as f:
jsn = json.load(f)
is failing; because it seems that ../ path refers to the Python script where mypkg is imported; and not mypkg relative path.
please advise with a simple example, how to set up a path inside the mypkg so that I can pass my.json to