如何使用argparse将任意字符串定义为可选参数?
例:
[user@host]$ ./script.py FOOBAR -a -b
Running "script.py"...
You set the option "-a"
You set the option "-b"
You passed the string "FOOBAR"
Run Code Online (Sandbox Code Playgroud)
理想情况下,我认为论点的立场无关紧要.即:
./script.py -a FOOBAR -b== ./script.py -a -b FOOBAR==./script.py FOOBAR -a -b
在BASH中,我可以在使用时完成此操作getopts.处理所有所需的开关,在的情况下环后,我有这样一行shift $((OPTIND-1)),并从那里我可以使用标准访问所有剩余的参数$1,$2,$3,等...
难道这样的事情exisit为argparse?