小编Ash*_*thi的帖子

parse_args() 的功能是什么,我需要在哪里传递参数

这是我的代码

我正在尝试学习 argparse 谁能解释我的代码

# enter code here
import argparse
parser= argparse.ArgumentParser()
parser.add_argument("radius",type=int,help="radius")
parser.add_argument("height",type=int,help="height")
args=parser.parse_args()
def add(radius,height):
   return radius+height
so=add(args.radius,args.height)
print("the sum is",so)
**
#this was the output
#usage: arg_parsedemo.py [-h] radius height
#arg_parsedemo.py: error: the following arguments are required:
#radius,height
Run Code Online (Sandbox Code Playgroud)

argparse python-3.x

4
推荐指数
1
解决办法
4307
查看次数

标签 统计

argparse ×1

python-3.x ×1