omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    Passing arguments with spaces in Run options

    Pythonista
    4
    4
    733
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • kenficara
      kenficara last edited by

      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?

      cvp 1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by

        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").

        1 Reply Last reply Reply Quote 0
        • cvp
          cvp @kenficara last edited by

          @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.
          

          1 Reply Last reply Reply Quote 2
          • superb-james
            superb-james last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors