当前位置:网站首页>parser. parse_ Args boolean type resolves false to true
parser. parse_ Args boolean type resolves false to true
2022-07-02 07:22:00 【lwgkzl】
Record a big pit , Many times , Never had a long memory ==!
problem
When I use parser When adding a parameter , Set it to bool Type of , Then the default value is True.
parser.add_argument("--some_argument", default=True, type=bool)However , When I type --some_argument=False When , The code comes out some_argument This parameter is still True.
I suspect that my coding posture is wrong , Changed --some_argument=false( A lowercase letter ) --some_argument=0 etc. , When the result code runs some_arguemnt Still True value .
reason
On the command line , Input false, perhaps “0” perhaps “False”, Are parsed into strings , After the string is converted to boolean type, it is like this :
>>> bool("false")
True
>>> bool("False")
True
>>> bool("0")
True
So no matter what we type in the command line , The code parses out True.
Solution
1. Simple and effective , From now on, do not set the default value to True Parameters of , Only set the default value to False Parameters of . In general, he defaults to False, If necessary, change the value of this parameter to True, You only need to enter this parameter on the command line =True That's it , In this way, the parameter will be resolved to True.
parser.add_argument("--some_argument", default=False, type=bool)2. The second is to use “store_true” This setting , The default effect is basically the same as the above
parser.add_argument("--some_argument", action="store_true")If you want this parameter to be True, Enter... On the command line --some_argument, If it is not entered, the default is False.
边栏推荐
- @Transational踩坑
- ORACLE EBS ADI 开发步骤
- 離線數倉和bi開發的實踐和思考
- Network security -- intrusion detection of emergency response
- view的绘制机制(三)
- Oracle EBS数据库监控-Zabbix+zabbix-agent2+orabbix
- Oracle general ledger balance table GL for foreign currency bookkeeping_ Balance change (Part 1)
- ssm垃圾分类管理系统
- Cognitive science popularization of middle-aged people
- parser.parse_args 布尔值类型将False解析为True
猜你喜欢

oracle apex ajax process + dy 校验

Proteus -- RS-232 dual computer communication

IDEA2020中测试PySpark的运行出错

Analysis of MapReduce and yarn principles

Principle analysis of spark

MySQL has no collation factor of order by

Agile development of software development pattern (scrum)

spark sql任务性能优化(基础)

【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization

Sparksql data skew
随机推荐
Pyspark build temporary report error
【信息检索导论】第六章 词项权重及向量空间模型
Spark SQL task performance optimization (basic)
Yolov5 practice: teach object detection by hand
叮咚,Redis OM对象映射框架来了
CAD secondary development object
ORACLE 11G SYSAUX表空间满处理及move和shrink区别
优化方法:常用数学符号的含义
SSM second hand trading website
Oracle 11.2.0.3 handles the problem of continuous growth of sysaux table space without downtime
使用Matlab实现:Jacobi、Gauss-Seidel迭代
DNS attack details
ERNIE1.0 与 ERNIE2.0 论文解读
2021-07-05c /cad secondary development create arc (4)
一份Slide两张表格带你快速了解目标检测
Sqli-labs customs clearance (less1)
中年人的认知科普
spark sql任务性能优化(基础)
【BERT,GPT+KG调研】Pretrain model融合knowledge的论文集锦
使用 Compose 实现可见 ScrollBar