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.


    Tool Extension arguments not in sys.argv

    Pythonista
    2
    4
    3379
    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.
    • eddo888
      eddo888 last edited by eddo888

      The arguments passed to the extension tool menu items inside pythonista are not in sys.argv

      1 Reply Last reply Reply Quote 0
      • eddo888
        eddo888 last edited by eddo888

        They are there however the $0 is added to the end of the list

        #!/usr/bin/env python
        
        import sys
        
        print(sys.argv)
        
        

        Produces

        ['/private/var/mobile/Containers/Shared/AppGroup/975867AB-70F6-4767-BDCD-372CAB8745F4/Pythonista3/Documents/tmp/argument.py', '--help', '/private/var/mobile/Containers/Shared/AppGroup/975867AB-70F6-4767-BDCD-372CAB8745F4/Pythonista3/Documents/tmp/argument.py']

        1 Reply Last reply Reply Quote 0
        • dgelessus
          dgelessus last edited by

          If you're referring to the wrench menu in Pythonista's editor - editor actions run from the wrench menu automatically get the path of the currently open file added to the end of sys.argv. This is to allow using "shell-style" scripts, which take filenames from sys.argv, as editor actions without having to modify them. I don't think there is a way to turn this off. Even if you have an empty editor tab open, it adds an empty string to sys.argv.

          1 Reply Last reply Reply Quote 0
          • eddo888
            eddo888 last edited by

            This can be used to resolve the issue

            if sys.argv[-1] == editor.get_path():
                    args = parser.parse_args(sys.argv[1:-1])
                else:
                    args = parser.parse_args()
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors