最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
python 接收处理外带参数的教程
时间:2018-12-04 编辑:猪哥 来源:一聚教程网
在执行python 代码的时候,有时候需要传递外面的参数进行处理
这个该怎么实现呢?
需要一个模块
from sys import argv
当然也可以直接只导入 sys
import sys
然后使用的时候, 用sys.argv也是可行的
import sys print "the script name is ", sys.argv[0] for num in range(1, len(sys.argv)): print "parameter %d is %s "% (num, sys.argv[num])
结果如下:
python test2.py this is a test last_parameter_Success the script name is test2.py parameter 1 is this parameter 2 is is parameter 3 is a parameter 4 is test parameter 5 is last_parameter_Success
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27