Forum Archive

Editor Module Question

procryon

Hey all, quick question about the editor module here. For the .openfile() function, it gives me an error when I put the name of the file I want to open. After reading on the forum, it says to use the filepath. As much as I tried to find a way, I’ve not been able to get the filepath. The file is just in a folder called Brain. Thanks in advance.

JonB

import os
os.path.expanduser('~/Documents/Brain/yourfile.txt')

Phuket2

@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

import os
_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)

print(my_path)

with open(my_path, "w") as f:
    f.writelines("Hello World")