当前位置:网站首页>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
边栏推荐
- What is JSON? First acquaintance with JSON
- Pytorch learning record (IV): parameter initialization
- Latex quick start
- 框架解析2.源码-登录认证
- PyQt5学习(一):布局管理+信号和槽关联+菜单栏与工具栏+打包资源包
- Solve the error: importerror: iprogress not found Please update jupyter and ipywidgets
- 建表到页面完整实例演示—联表查询
- 开发环境 EAS登录 license 许可修改
- 类的加载与ClassLoader的理解
- JDBC连接数据库
猜你喜欢
无监督去噪——[TMI2022]ISCL: Interdependent Self-Cooperative Learning for Unpaired Image Denoising
Opensips (1) -- detailed process of installing opensips
Development environment EAS login license modification
Anaconda
Pytorch学习记录(十三):循环神经网络((Recurrent Neural Network)
You cannot access this shared folder because your organization's security policy prevents unauthenticated guests from accessing it
Contrôle automatique (version Han min)
Pytoch -- data loading and processing
Pytorch学习记录(十二):学习率衰减+正则化
编程记录——图片旋转函数scipy.ndimage.rotate()的简单使用和效果观察
随机推荐
Use Matplotlib. In Jupiter notebook Pyplot server hangs up and crashes
开发环境 EAS登录 license 许可修改
Configure domestic image accelerator for yarn
深入理解去噪论文——FFDNet和CBDNet中noise level与噪声方差之间的关系探索
RedHat6之smb服务访问速度慢解决办法记录
EditorConfig
域内用户访问域外samba服务器用户名密码错误
Pytorch learning record (XII): learning rate attenuation + regularization
字符串(String)笔记
PyQy5学习(二):QMainWindow+QWidget+QLabel
Pytorch Learning record (XIII): Recurrent Neural Network
关于二叉树的遍历
Software architecture design - software architecture style
Record a project experience and technologies encountered in the project
自动控制(韩敏版)
The difference between cookie and session
Pytorch学习记录(九):Pytorch中卷积神经网络
建表到页面完整实例演示—联表查询
delete和truncate
Pytorch introduction notes - use a simple example to observe the output size of each layer of forward propagation