当前位置:网站首页>Argparse command line passes list type parameter
Argparse command line passes list type parameter
2022-06-13 01:04:00 【kaims】
Error model ( Not recommended , It is not convenient to transfer parameters dynamically ):
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--alpha', type=list, default=[0.35, 0.25, 0.40])
args = parser.parse_args()
if __name__ == '__main__':
print(args.alpha)

Correct example 1 :
import argparse
parser = argparse.ArgumentParser()
## nargs='+' Accept 1 Two or more parameters ,
## nargs='*' Accept zero or more
parser.add_argument('--list', nargs='+', help='<Required> Set flag', required=True)
args = parser.parse_args()
if __name__ == '__main__':
print(args.list)
The parameters passed in at runtime are separated by spaces , The operation results are as follows :
Correct example 2 :
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--ll', action='append', help='<Required> Set flag', required=True)
args = parser.parse_args()
if __name__ == '__main__':
print(args.ll)
Running examples and results :
reference :
https://zhuanlan.zhihu.com/p/258446208
边栏推荐
- [Latex] 插入图片
- 408 true question - division sequence
- MySQL transaction
- Binary tree traversal - recursive and iterative templates
- Pysmb usage
- Characteristics of transactions - persistence (implementation principle)
- Google play console crash information collection
- 軟件測試的幾種分類,一看就明了
- How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic benefits of ASI, VR, arbr, DPO and trix indicators
- Androi天氣
猜你喜欢
![[JS component] previous queue prompt](/img/79/9839f68b191b0db490e9bccbeaae1d.jpg)
[JS component] previous queue prompt

切线与切平面

. The way to prove the effect of throwing exceptions on performance in. Net core

spiral matrix visit Search a 2D Matrix

How to choose stocks? Which indicator strategy is reliable? Quantitative analysis and comparison of strategic benefits of ASI, VR, arbr, DPO and trix indicators

Introduction to ROS from introduction to mastery (zero) tutorial

三栏简约typecho主题Lanstar/蓝星typecho主题

Expression tree - medium order printout
![[Latex] 插入圖片](/img/0b/3304aaa03d3fea3ebb93b0348c3131.png)
[Latex] 插入圖片
![[JS] battle chess](/img/1f/83ca6bcb000a5567dc6d3b72463ff8.jpg)
[JS] battle chess
随机推荐
Addition and modification of JPA
The scope builder coroutinescope, runblocking and supervisorscope of kotlin collaboration processes run synchronously. How can other collaboration processes not be suspended when the collaboration pro
[JS component] dazzle radio box and multi box
[latex] insert picture
ROS从入门到精通(零) 教程导读
Pipeline pipeline project construction
[imx6ull] video monitoring project (USB camera +ffmepeg)
[network protocol] problems and solutions in the use of LwIP
How to handle different types of data
Canvas airplane game
How many rounds of deep learning training? How many iterations?
[JS component] customize the right-click menu
Five classic articles worth reading
The seventh finals of the Blue Bridge Cup
.net core 抛异常对性能影响的求证之路
[virtual machine] notes on virtual machine environment problems
Mathematical knowledge arrangement: extremum & maximum, stagnation point, Lagrange multiplier
[JS component] browse progress bar
[server data recovery] successful cases of data loss recovery during data migration between storage servers
Lessons learned from the NLP part of the course "Baidu architects hands-on deep learning"