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.
Import binary files into Pythonista workspace
-
I have several of binary files in my iCloud Drive that I want to analyze with Python(ista). Using either the Files app, or Pythonista's import dialog, I can import many types of files into my Pythonista workspace, for example, .txt, image files and PDF files.
However, importing .zip files or .sqlite3 database files (or many other binary file types) does not work for me.
Any advice for how I can process arbitrary files with Pythonista?
-
https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile.open
You can open an arbitrary binary file: with open(in_file_path, 'rb') as in_file: print(in_file.read(100))
-
That works once I have the file inside the Pythonista container. However, Pythonista seems to only allow import of certain kinds of file extensions into the container. Files with zip extension for example are blocked.
I found a workaround: From Files app, import the .zip file into Working Copy. In Working Copy, rename the file extension to .txt, then share from Working Copy into Pythonista iCloud Folder. Now just read the "text" file with open("foo.txt", "rb") and interpret in binary mode.
But why not allow import of arbitrary files in the first place?
-
@lucas2301 from the Files app, you can
select any type of file,
share it,
run Pythonista script,
select standard "import file"and the file arrives in the Pythonista root...
-
Thanks! "Run Pythonista Script" and then "import" works.