当前位置:网站首页>Common programming records - parser = argparse ArgumentParser()
Common programming records - parser = argparse ArgumentParser()
2022-04-23 06:00:00 【umbrellalalalala】
In many pytorch Written in the AI project , Can see such a sentence :parser = argparse.ArgumentParser(), This article simply records their usage
Partial content reference :
https://blog.csdn.net/lizhiyuanbest/article/details/104975848
Catalog
The way 1— Single parameter
establish a.py:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", help="display a square of a given number", type=int)
args = parser.parse_args()
s = args.square ** 2
print(s)
Command line execution :
$ python a.py 2
4
The way 2— Multiple parameters
establish b.py:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", help="display a square of a given number", type=int)
parser.add_argument("add1", help="display a sum of two given numbers", type=int)
parser.add_argument("add2", help="display a sum of two given numbers", type=int)
args = parser.parse_args()
s = args.square ** 2
a = args.add1 + args.add2
print(s)
print(a)
Command line execution results :
$ python b.py 2 10 20
4
30
It can be seen that three integers are assigned to three parameters in order
The way 3— Out of order assignment
establish c.py:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--square", help="display a square of a given number", type=int)
parser.add_argument("--add1", help="display a sum of two given numbers", type=int)
parser.add_argument("--add2", help="display a sum of two given numbers", type=int)
args = parser.parse_args()
s = args.square ** 2
a = args.add1 + args.add2
print(s)
print(a)
️ Note that the parameter is preceded by --
Command line operation mode 1:
$ python c.py --square 2 --add1 10 --add2 20
4
30
Command line operation mode 2( Out of order ):
$ python c.py --add1 2 --add2 10 --square 20
400
12
knock pytorch It should be enough for students to master these
版权声明
本文为[umbrellalalalala]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230543450923.html
边栏推荐
- Get the value of state in effects in DVA
- What is JSON? First acquaintance with JSON
- 事实最终变量与最终变量
- Chapter 3 of linear algebra - Elementary Transformation of matrix and system of linear equations
- 创建二叉树
- 去噪论文阅读——[RIDNet, ICCV19]Real Image Denoising with Feature Attention
- 线性代数第三章-矩阵的初等变换与线性方程组
- PyTorch笔记——实现线性回归完整代码&手动或自动计算梯度代码对比
- Linear algebra Chapter 2 - matrices and their operations
- EditorConfig
猜你喜欢

sklearn之 Gaussian Processes

解决报错:ImportError: IProgress not found. Please update jupyter and ipywidgets

String notes

图像恢复论文简记——Uformer: A General U-Shaped Transformer for Image Restoration

开发环境 EAS登录 license 许可修改

Illustrate the significance of hashcode

你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问

delete和truncate

Automatic control (Han min version)

Pytorch学习记录(三):神经网络的结构+使用Sequential、Module定义模型
随机推荐
Graphic numpy array matrix
线性代数第三章-矩阵的初等变换与线性方程组
You cannot access this shared folder because your organization's security policy prevents unauthenticated guests from accessing it
自动控制(韩敏版)
The attendance client date of K / 3 wise system can only be selected to 2019
创建二叉树
Pytorch学习记录(五):反向传播+基于梯度的优化器(SGD,Adagrad,RMSporp,Adam)
去噪论文——[Noise2Void,CVPR19]Noise2Void-Learning Denoising from Single Noisy Images
LDCT图像重建论文——Eformer: Edge Enhancement based Transformer for Medical Image Denoising
PyQt5学习(一):布局管理+信号和槽关联+菜单栏与工具栏+打包资源包
创建企业邮箱账户命令
JDBC操作事务
DBCP使用
Numpy common function table sorting of data processing
框架解析2.源码-登录认证
C3P0数据库连接池使用
Pyqy5 learning (2): qmainwindow + QWidget + qlabel
PyTorch笔记——通过搭建ResNet熟悉网络搭建方式(完整代码)
PreparedStatement防止SQL注入
Practical operation - Nacos installation and configuration