python3 运行argparse XX.py: error: the following arguments are required: N An exception has occurred,
Spyder(python 3.6) 运行含argparse模块的程序
# max sum.py
import argparseparser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('integers', metavar='N', type=int, nargs='+',help='an integer for the accumulator')
parser.add_argument('--sum', dest='accumulate', action='store_const',const=sum, default=max,help='sum the integers (default: find the max)')args = parser.parse_args()
print(args.accumulate(args.integers))
出现如下错误:
usage: max sum.py [-h] [–sum] N [N …]
max sum.py: error: the following arguments are required: N
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
E:\anaconda3\lib\site-packages\IPython\core\interactiveshell.py:2971: UserWarning: To exit: use ‘exit’, ‘quit’, or Ctrl-D.
warn(“To exit: use ‘exit’, ‘quit’, or Ctrl-D.”, stacklevel=1)
错误原因:
没有输入参数
解决办法:
打开Anaconda Prompt 或 cmd.exe,用 命令 python xx.py 参数 执行。
参考:https://docs.python.org/zh-cn/3.6/library/argparse.html#argumentparser-objects
another example:
# temp.py
import argparse
parser = argparse.ArgumentParser() # 声明一个parser
parser.add_argument("parg") # 位置参数,第一个出现的参数赋值给parg
parser.add_argument("--digit",type=int,help="输入数字") # 通过 --echo xxx声明的参数,为int类型
parser.add_argument("--name",help="名字",default="default") # 同上,default 表示默认值
args = parser.parse_args()# 读取命令行参数
# 调用这些参数
print(args.parg)
print("echo ={0}".format(args.digit))
print("name = {}".format(args.name))
python3 运行argparse XX.py: error: the following arguments are required: N An exception has occurred,相关推荐
- (理解和3种方法完全解决pycharm报错)main.py: error: the following arguments are required: -d/--dataset
文章目录 背景 理解 完全解决 方法1 方法2 方法3 背景 很多人只说解决方案,却不说原因,遂有此篇. 在pycharm中直接运行如下代码main.py报错: import argparse if ...
- train.py: error: the following arguments are required: --config解决办法
train.py: error: the following arguments are required: --config解决办法 最近在跑github上的深度学习开源项目,在导入项目运行trai ...
- main.py: error: the following arguments are required:
报错 "main.py: error: the following arguments are required:" 1.首先查看报错信息 如图下图所示 main.py: erro ...
- error: the following arguments are required
[1]usage: run_one_image.py [-h] [--use_cuda] [--use_cython] image_path templ ...
- “ error: the following arguments are required: --model, --data“解决办法
"error: the following arguments are required: --model, --data"解决办法 问题描述 解决办法 问题描述 pycharm运 ...
- error: the following arguments are required: cfg_file
error: the following arguments are required: cfg_file 这里一共列举4种情况: 1)参数前面没有加-- 2)参数没有加default值 3)没有这个 ...
- error: the following arguments are required: img, config, checkpoint
目录 01问题描述 02 问题分析 03 解决方案 01问题描述 在验证mmdetection环境是否安装成功的时候,出现如下错误: error: the following arguments a ...
- error: the following arguments are required: --cfg
先看错误代码: parser.add_argument('--cfg', type=str, required=True, metavar="FILE", help='path t ...
- 【问题记录】usage: nn_train.py [-h] -d DATASET -m MODEL -l LABEL_BIN -p PLOT nn_train.py: error: the follo
文章目录 一.问题描述 二.问题解决 一.问题描述 昨晚的问题没有记录全,这仍是对于昨晚问题的一个记录. 同昨天的代码.在跑一段神经网络代码时,遇到如下问题: 内容为: usage: nn_train ...
最新文章
- 关于docker的存储驱动
- spring cloud 定时任务
- 强大的NVAE:以后再也不能说VAE生成的图像模糊了
- Web框架之Django_02基本操作(Django项目启动配置、数据库连接、orm、增删改查)
- 详解:数据库名、实例名、ORACLE_SID、数据库域名、全局数据库名、服务名
- OSPF的LSA类型 ——连载五自治系统外部的LSA
- linux下的c语言控制灯闪烁,C语言实现LED灯闪烁控制
- mysql数据库搜索引擎要先进入_Mysql搜索引擎都有哪些区别
- es6 next()方法的参数
- java读取一个应用程序_Java IO – 在写入其他应用程序时读取一个大文件
- #6282. 数列分块入门 6
- python c语言接口_C/C++ 提供 Python 接口
- 为什么说算法是程序猿“修仙”的必经之地?
- python创建gui界面_你要的 Python 创建 GUI 用户界面程序,来咯
- linux6禁用屏幕保护程序,禁用屏幕保护程序(ScreenSaver Disabled)
- matlab中做出球面和圆柱面,matlab画柱面与球面切线
- 阿里云mysql导出表,mysql导出数据库表数据
- 【vue】浏览器播放提示音audio
- 河南民办计算机大学排名,2021河南民办大学排名 河南最好的民办本科高校有哪些...
- 留个底 人人乐旁靓房房东出租,我是房东
热门文章
- word排版时如何保证每张图片大小一样?
- 商标取名,你学会了吗?
- linux泛目录,黑帽seo蜘蛛池搭建泛目录快排教程
- 一些下载资料(电子通信类)的论坛
- 微电影广告具有哪些特点?
- 【Android Assimp】免积分 一步编译assimp(自己整合的编译工具)(内含已编译so库下载)
- Linux 学习笔记(八):时间片轮转调度
- ubuntu10.10中安装eyeos2.2
- eyeOS 2.0安裝指南 - 中文版 (附英文版)zt
- android视频播放器ui,ArtVideoPlayer 一个灵活的Android视频播放器,支持全屏,小屏播放...