Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
How can I load a txt file from my iPad in my code?
-
I don’t know how to access to a txt file saved in the Documents directory of Pythonista
-
@gaerobin if you want to read it as a whole
with open('YourFile.txt',encoding='utf-8') as f: t = f.read()
If you want to read in lines
with open('YourFile.txt',encoding='utf-8') as f: lines = f.readlines()
-
@cvp
Thanks but don’t I have to tell the path to find the file? Just like this I have an error 2 No such file or directory -
@gaerobin sure you have to define the path. I thought that you didn't know how to read a file, not where, sorry
-
My pb is to know how to define the path system on an ipad
-
@gaerobin try
import os path = os.path.expanduser('~/Documents/your directory/your file.txt') with open(path,encoding='utf-8') as f: t = f.read() print(len(t))
And print(path) to see the whole path. Hexadecimal digits identify your device in
/private/var/mobile/Containers/Shared/AppGroup/1B829014-77B3-4446-9B65-034BDDC46F49/Pythonista3/Documents/your directory/your file.txt
-
Thanks for your help