#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import argparse

parser = argparse.ArgumentParser(description="程序描述")

# 互斥组(组内的各参数不能同时使用)
group = parser.add_mutually_exclusive_group()
group.add_argument("-a", "--aaa", help="a参数描述", action="store_true")
group.add_argument("-b", "--bbb", help="b参数描述", type=int)
group.add_argument("-c", "--ccc", help="c参数描述")
args = parser.parse_args()

if args.aaa:
    pass
elif args.bbb:
    pass
elif arg.ccc:
    pass
else:
    parser.print_help()

The Python Standard Library » Generic Operating System Services » argparse — Parser for command-line options, arguments and sub-commands

标签: Python

评论已关闭