当前位置:网站首页>Deep understanding of add in argparse module_ Argument parameters (such as action)
Deep understanding of add in argparse module_ Argument parameters (such as action)
2022-06-11 08:11:00 【Interval】
List of articles
Easy to use
import argparse
parser = argparse.ArgumentParser(description="Deep Gaussian Processes on MNIST")
parser.add_argument("-n", "--num-epochs", default=5, type=int)
parser.add_argument("-t", "--num-iters", default=60, type=int)
parser.add_argument("-b", "--batch-size", default=1000, type=int)
parser.add_argument("-lr", "--learning-rate", default=0.01, type=float)
args = parser.parse_args()
print(args.num_epochs)
Output results :
5
User specified parameters
Next, let's take the example above , Suppose this python The name of the file is main.py. If we need to Runtime Change the value of the parameter , Can be as follows :
python main.py -n 6 -t 100# The parameter n,t The values of are changed from the default values to 6,100.
python main.py --num-epochs 6 --num-iters 100# Equivalent form
This is not the first example , It is special , But it will be used later .
python main.py -x
You can see , Its special feature is that it is not followed by a value that needs to be specified . Let's reveal it first , In fact, this is not uncommon , To recall linux The style of .
Parameters
We can see from above add_argument There are many interface options , for example default,type wait , What are their respective uses ?
- first "-x", Just for python Abbreviation when the system reads the input .
- the second "–xxx", As the real name of this parameter , That is, when this parameter is used, it is args.xxx, instead of args.x.
- default, The default value of this parameter .
- type, Data type of parameter , for example int,float,str,list etc. .
- required, The default is false, If true, And there is no default value , Indicates that this parameter must be specified by the user , Otherwise, the program reports an error .
- action,action=‘store_true’/‘store_false’. The argument to use this option must be a boolean variable . among store_true Express : The user specified this parameter , So this parameter is true. What does a user specify ? For example, the special example above ,python main.py -x, It designates x, that x Will become True. Empathy store_false.
- choice, That is, the value range of the parameter , Can help you automatically determine whether to cross the line . for example [1,2], Indicates that only values can be taken 1 perhaps 2.
- help, Interpretation of parameters , It is equivalent to annotation , I'm afraid I forget .
- nargs, The value can be ["*","+", Positive integer ] etc. , That is, this parameter is a list ,"*" Represents any parameter .“+” Represents at least one parameter . A positive integer represents so many parameters . Suppose this parameter is called people, And nargs=2. So the order is as follows :python main.py --people x y. that people=[“x”,“y”].
This article only talks about some common parameters and functions .
In fact, there are some other parameters , Here's not a list , Another example nargs The value of can also be “?". What does this mean , And examples , It is highly recommended that you refer to python Official documents of https://docs.python.org/3/. This thing is always the best .


边栏推荐
- 2022.6.6 extra long growth simulation
- Record a murder case caused by ignoring the @suppresslint ("newapi") prompt
- Selenium click the floating menu and realize the functions of right mouse button
- Bladed入門教程(視頻)
- How CSDN reports plagiarized articles
- Semiconductor memory classification
- TypeScript-在koa中配置TS和使用koa-router
- Jupyter notebook code completion plug-in + Solution
- 彻底记住ImageView的background和src的区别
- Image processing operation record
猜你喜欢

用 Keras/TensorFlow 2.9 创建深度学习模型的方法总结

(transformation) tree, binary tree and forest transformation principle

Record a murder case caused by ignoring the @suppresslint ("newapi") prompt

Return in foreach and break in for

学习《缠解论语》

How to do well in empty state design? Look at this comprehensive summary

进程控制:进程等待(回收子进程)

Figure seamless database integration tushare interface

嵌入式软件面试问题总结

Collation of basic knowledge of intermediate development of Andrews (for interview)
随机推荐
AttributeError: module ‘tensorflow. compat. v2.__ internal__‘ has no attribute ‘register_ clear_ session_
Study the Analects of entanglement
TypeScript-在koa中配置TS和使用koa-router
TypeScripy-类的基本使用
node报错整理
Project training - clonemon
DAMENG 数据库登陆
Solve notimplementederror: layer XX has arguments in`__ init__` and therefore must override `get_ config`
TypeScript-声明合并
Typescript type protection
TypeScript-接口和类型别名异同
Tutoriel de démarrage bladed (vidéo)
Semiconductor memory classification
ConstraintLayout中使用Guideline限制控件最大宽度
Method summary of creating deep learning model with keras/tensorflow 2.9
JSP development model
How to find the complementary sequence of digraph
YUV数据的裁剪与重叠
项目实训-克隆门
Use guidelines in constraintlayout to limit the maximum width of controls