you can set the base path as follows
import os from pathlib import Path # Make sure in source path: os.chdir(os.path.abspath(os.path.dirname(__file__))) homepath = Path('.') onebelow = homepath / 'onebelowname' # Also, if you want path created if it doesn't already exist then add onebelow.mkdir(exist_ok=True) # to create a file in that directory: mynewfile = onebelow / 'mynewfilename' # To open that file for writing text with mynewfile.open('w') as fp: fp.write('whatever')