I have a python project on my pc, how can I import to Pythonista on iPad?
-
I have a project with 3 files: a py source code, an input file and an output file. I need to copy those three files on the iPad to run that code. I've tried, but I cannot find how.
I thought it should be possibile with the App Extension, but when I open the .py file with that, it doesn't let me save it inside the app.Can you help me?
Thanks in advance, best regards.
-
I have them in my pc and I can share them with SMB/samba, or on http server.
I use owncloud and it's a possibility too.
I should be very nice to be able to import a zip file and extract on a directory (new project) on pythonista.
I've also tried to create a CSV file but pythonista adds me an extension (.txt, .py, etc).
Using the usb port of the ipad, I can only put files on DCIM.
Why it's so hard to copy files on IOS?
-
Hey, also you could use Ivoah's webIDE
https://forum.omz-software.com/topic/2714/webide
https://github.com/Ivoah/WebIDE
-
@aronchi one more thing. You can add this script to your app extension for Pythonista. If you have a raw text file hosted via a server, if you go to it in safari and run this extension on it, it will ask you to name the file and then download that text. I think you might need to manually create a "Downloads" folder in documents.
Disclaimer - I don't remember where I got this file. It might have been @ccc or @Webmaster4o or maybe @TutorialDoctor ...sorry!
# coding: utf-8 import requests import appex from console import alert, input_alert import os.path import os def main(): if not appex.is_running_extension(): alert("Error", "This script is intended to be run from the sharing extension.", "Exit", hide_cancel_button=True) return url = appex.get_url() if not url: alert("ERROR", "No input URL found. Execute this script from the sharing extension.", "Quit", hide_cancel_button=True) return root_path = "../../Documents/Downloads/" while True: filename = input_alert("Download File", "You have chosen to download file at URL:\n " + url + "\n\nEnter filename to save locally. Press Cancel to abort.") filename = root_path+filename if os.path.exists(filename): if os.path.isfile(filename): confirm = alert("Warning", "File %s exists. Overwrite?" % filename, "Overwrite", "Change Filename", hide_cancel_button=True) if confirm == 1: os.remove(filename) break else: alert("Critical Error.", "Path exists but is not a file. Exiting.", "Exit", hide_cancel_button=True) return else: break r = requests.get(url) if r.status_code != 200: alert("Invalid HTTP Response: %d, Exiting." %r.status_code, "Exit", hide_cancel_button=True) return confirm = alert("Confirm Download", "Text length: %d, Press OK to Save, Cancel to Quit" %len(r.text), "Save", "Cancel", hide_cancel_button=True) if confirm == 1: outfile = open(filename, "w") for line in r.text: outfile.write(line) outfile.close() alert("Success", "File Saved.", "Exit", hide_cancel_button=True) r.close() return if __name__ == '__main__': main()
-
I use a script of @omz see which starts a server on your iPad! You can access your Pythonista folders/files from/to your PC/Mac with your web browser.
-
An important question: some text files are encoded.
Mine are unix - UTF-8If I copy and paste the content, what's the encoding of the file created?
and with that download extesion, will it change the charset?
-
Downloading the file with the extesion I have an unicodeDecodeError (ascii codec can't decode character \xe2 in position 0: ordinal not in range).
-
If you look at the script above, you will see that the first line is
# coding: utf-8
This is done in compliance withhttps://www.python.org/dev/peps/pep-0263/
https://docs.python.org/3/howto/unicode.htmlAnd enables Python, Editors, etc. to understand the coding of the Python file itself.
I believe that copy and paste as well as the transfer tool will preserve encoding intact but I could not guarantee that.
Python 2 and Python 3 have different ways of dealing with Unicode. Read the How-To above.
-
I wrote an smb client, but first you have to copy-and-paste this repo.
Just add this line if you're using Pythonista3 to the py file#! python2
-
The problem with unicode is not in python code, but in input files.
With stash and wget I solved.I'll try also the smb, thanks.
Pythonista is a great editor, better than most Desktop ones.
It would be great to add a system to symplify the python projects downloading and installation (egg system market?) , because python is a great scripting and programming tool, and It would add a lot of functionalities to ios.
-
iOS apps are not allowed to download or import executable code, this is an Apple limitation. That's why Pythonista is not an "Open In" target (anymore) and why there is no built-in way to download scripts from online. But thankfully you can use the Pythonista app extension to copy files into Pythonista and
wget
to download files from online.