@procryon, my example is same as @JonB , except I just split it up so you see the root dir for Pythonista etc. Functionally the same. Just more step by step
_root_path = os.path.expanduser('~/Documents')
_my_dir = 'Brain'
_my_file_name = 'yourfile.txt'
my_path = os.path.join(_root_path, _my_dir, _my_file_name)
with open(my_path, "w") as f: