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.
Hi. There's a couple ways you can do this.
1.) Manually: Use Dropbox/some other tool to get the scripts on your iPad in any form. Copy the contents of each script, create a new script in Pythonista, name it as you'd like, and then paste the contents.
2.) DropBox sync: Use the dropboxsync.py script found elsewhere on this forum. You need to setup a Dropbox developer account and get a token. (I've been using the same version of that script that isn't perfect and has some problems with case, if anybody else knows what the latest greatest version of that script is please chime in)
3.) git / github : If you're familiar with using git/ github, you can create a repo in github. Then, install Stash (https://github.com/ywangd/stash), launch it, choose the directory and clone there using standard git commands.
Let us know if you have any questions.
Where are your 3 files stored?
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?
@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.
# 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()
An important question: some text files are encoded.
Mine are unix - UTF-8
If 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-8This is done in compliance with
And 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
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
wgetto download files from online.