Argparse usage of Python Library

Time:2021-5-29

Argspark is the standard module of Python command line parsing

Download address:https://pypi.org/project/argp…

code

import argparse

Parser = argparse. Argumentparser (description ='a number passed in the command line ')
parser.add_ Argument ("square", help = "please enter a number", type = int)
parser.add_ argument("input_ STR ", help =" please enter a letter ", type = STR)
args = parser.parse_args()
print(args.square ** 2  )
print(args.input_str)


#Parser = argparse. Argumentparser (description ='multiple numbers passed in the command line ')
# parser.add_ argument("more_ "Int", help = "please enter a letter", nargs = '+', type = int)
# args = parser.parse_args()
# print(args.more_int)

#Set whether the parameter is required. Required = true
#Set multiple parameters nargs = '+'
#Set the default value of the parameter default ='ha '

Implementation:

python3 test2.py  5  k  
25
k

Welcome to several life apps developed by flutter

Here’s the apple version

Here’s the Android version