python 接收处理外带的参数方法,python外带
python 接收处理外带的参数方法,python外带
在执行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
以上这篇python 接收处理外带的参数方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编橙之家。
相关内容
- 对python 命令的-u参数详解,python-u参数详解
- Python推导式简单示例【列表推导式、字典推导式与集合
- 浅谈python中str字符串和unicode对象字符串的拼接问题,
- Python 从相对路径下import的方法,pythonimport
- 对python的bytes类型数据split分割切片方法,
- 解决python中无法自动补全代码的问题,解决python补全代
- python无限生成不重复(字母,数字,字符)组合的方法,py
- Python发送邮件功能示例【使用QQ邮箱】,python发送邮件
- python 实现数字字符串左侧补零的方法,python字符串
- 浅谈python下tiff图像的读取和保存方法,pythontiff
评论关闭