1. 程式人生 > >python的命令行參數處理

python的命令行參數處理

form ces 參數 favor serve sele osi ntp help

import argparse
 
# A position argument
func_choice = {client : client function, "server" : "server function"}

# parser
parser = argparse.ArgumentParser(description = "Select your favorite function")
# add argument
parser.add_argument(role, choices = func_choice, help = "select your role
") parser.add_argument("-p", type = int, help = "select your port") # parse args = parser.parse_args() print("You select role {0} and port {1}".format(func_choice[args.role], args.p))

python的命令行參數處理