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
-
The arguments passed to the extension tool menu items inside pythonista are not in sys.argv
-
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']
-
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 fromsys.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 tosys.argv
. -
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()