当前位置:网站首页>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.
边栏推荐
- SSM garbage classification management system
- Error in running test pyspark in idea2020
- Pyspark build temporary report error
- pySpark构建临时表报错
- Yaml file of ingress controller 0.47.0
- 【论文介绍】R-Drop: Regularized Dropout for Neural Networks
- MySQL composite index with or without ID
- 【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization
- view的绘制机制(三)
- Cognitive science popularization of middle-aged people
猜你喜欢
mapreduce概念和案例(尚硅谷学习笔记)
SSM second hand trading website
MySQL has no collation factor of order by
Only the background of famous universities and factories can programmers have a way out? Netizen: two, big factory background is OK
Ceaspectuss shipping company shipping artificial intelligence products, anytime, anywhere container inspection and reporting to achieve cloud yard, shipping company intelligent digital container contr
ssm超市订单管理系统
Cognitive science popularization of middle-aged people
Implementation of purchase, sales and inventory system with ssm+mysql
DNS攻击详解
Take you to master the formatter of visual studio code
随机推荐
使用MAME32K进行联机游戏
JSP智能小区物业管理系统
Feeling after reading "agile and tidy way: return to origin"
PM2 simple use and daemon
ARP attack
Data warehouse model fact table model design
ssm垃圾分类管理系统
SSM supermarket order management system
oracle EBS标准表的后缀解释说明
叮咚,Redis OM对象映射框架来了
ssm+mysql实现进销存系统
Check log4j problems using stain analysis
TCP attack
使用Matlab实现:弦截法、二分法、CG法,求零点、解方程
Pyspark build temporary report error
ORACLE EBS 和 APEX 集成登录及原理分析
ORACLE EBS ADI 开发步骤
【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization
spark sql任务性能优化(基础)
【信息检索导论】第一章 布尔检索