How to run a python file in icloud when open it using files app.
-
I have a python file in icloud and I want to run it.
When I press share button. I see a "Run Pythonista Script" and press it. It show three optionAll Scriipts
Scatchpad
ConsoleBut none of it is execute it . It just open a console or scatchpad.
And I don' want to new a file and copy the file content to the new file then run it
-
This is not currently possible. The "Run Pythonista Script" action doesn't mean "run this file with Pythonista", it means "run a Python script that works with this file". At the moment the only way to run a Python script from iCloud is to copy and paste the text into Pythonista.
The current beta version of Pythonista has much better integration with iCloud and the Files app, and it allows opening files in Pythonista directly, without copying them. I don't know when the next release of Pythonista will come out though.
-
Instead of copy-paste, you could also create a script that runs other scripts in the share sheet.
Create a new file in the main app, call it something like “Run Script.py and add the following code:
import appex, os, runpy def main(): py_file = appex.get_file_path() if not py_file or os.path.splitext(py_file)[1] != '.py': print('No Python file') return runpy.run_path(py_file) if __name__ == '__main__': main()
Then in the “Run Pythonista Script” action, tap the Edit button, then (+), and select the script you just created. This will create a shortcut in the share extension to run this script, which will run the script you selected before invoking the share sheet.