我有一个小脚本,我需要它能够接受带有值和没有值的参数。
./cha.py --pretty-xml
./cha.py --pretty-xml=5
Run Code Online (Sandbox Code Playgroud)
我有这个。
parser.add_argument('--pretty-xml', nargs='?', dest='xml_space', default=4)
Run Code Online (Sandbox Code Playgroud)
但是,当我在xml_space中使用--pretty-xml时将为“ none”。如果我不写此参数,则在xml_space中存储默认值。我需要完全相反。