Peter Otten <__pete...@web.de> writes: > I'm not sure about this one; one purpose of REMAINDER is to pass on the > unprocessed arguments to another program/script, and this might follow the > same convention. Should > > parser.add_argument('-v', '--verbose', action='store_true') > parser.add_argument('cmd_args', nargs=argparse.REMAINDER) > args = parser.parse_args() > subprocess.call(["rm"] + args.cmd_args) > > $ my_prog -v -- -r foo > > attempt to delete two files "-r" and "foo" or remove the "foo" directory? > The first is the safer alternative, and as you say stripping the "--" is > easy.
I think it should be the second. If the caller wants it to be treated as a list of files rather than a list of arguments, it should be using subprocess.call(["rm", "--"] + args.cmd_args). The purpose is, as you said, to pass the *unprocessed* argument. -- has been processed by being interpreted as a terminator for the argument list. I have a script (it's a shell script, not a python script) where I actually do something similar... it does some setup, then calls ssh. If I want to pass some options directly to ssh, I call it as: "scriptname -script-option -- -ssh-option remote-command" -- https://mail.python.org/mailman/listinfo/python-list