I prefer to specify patterns starting from the file directory
import os script_dir = os.path.dirname(__file__) file_path = os.path.join(script_dir, 'relative/path/to/file.json') with open(file_path, 'r') as fi: pass
This eliminates the need to worry about working directory changes. And also it allows you to run a script from any directory using the full path.
python script/inner/script.py
or
python script.py
source share