Sure is. You just need to know the file path of the external app. Create a script called test.py
with the following content in Working Copy. Open that repo in Pythonista. Run the script.
import os
cwd = os.getcwd()
print(cwd)
with open(f"{cwd}/test.py") as f:
print(f.readlines())
This prints the full path to the directory of test.py
, then reads and prints the contents of that file. Reading other files from the same directory is trivial. Note that this only works for files in folders which you have already opened in Pythonista (Pythonista doesn’t have permission to access any other external files), and that it only works from the main Pythonista app (it won’t work from the widget or share sheet, because those are separate processes with distinct permissions).
I see the following output:
/private/var/mobile/Containers/Shared/AppGroup/5BAD0E84-52A4-4FD2-8008-A2508B4F433F/File Provider Storage/Repositories/my-repo
['import os\n', '\n', 'cwd = os.getcwd()\n', 'print(cwd)\n', 'with open(f"{cwd}/test.py") as f:\n', ' print(f.readlines())\n']