Forum Archive

Passing arguments with spaces in Run options

kenficara

Under the wrench icon in Pythonista there is a “Run options” button with an input field to add arguments. If I enter “first argument”, “second argument” into that field, argv will contain [“first”, “argument”, “second”, “argument”]. How does one pass arguments with spaces here?

ccc

https://docs.python.org/3/library/urllib.parse.html#url-quoting contains the general idea.
TL;DR Try s.replace(" ", "+") and if that does not work, try s.replace(" ", "%20").

cvp

@kenficara see local doc

Example: pythonista://MyScript?action=run&args=foo%20bar

When you pass a single string with the args URL parameter, the string is split by spaces (the space is encoded as %20 here) and sys.argv would be [<script_path>, 'foo', 'bar'] in this example.

If you want to pass arguments that contain spaces, you have to enclose them in double quotes (as you would in a classic shell).

This is basically the same as running a script by long-pressing the run button.

superb-james

If you want to save a large amount of your money from Aacomas then click the link and get a large variety of quality coupons from Aacomas. Aacomas discount