linux 自动发邮件脚本 Python笔记-脚本参数传递
编写Python脚本辅助卡盟,经常需要从外部传递参数linux 自动发邮件脚本,此时需要用到 getopt 和 sys。
语法如下:
getopt.getopt(args, shortopts, longopts=[])
args 参数列表
shortopts 短参数,如:-h
longopts 长参数,如:–help
sys.argv[] 是一个列表linux 自动发邮件脚本,包含命令行所有信息
sys.argv[0] 是被调用的脚本文件名或全路径
sys.argv[1:] 之后的元素就是我们从程序外部输入的
示例:
import getopt
import sys
def print_help():
print('\n-a value of a')



[root@test1 dataC]# python3 test.py
-h --help
[root@test1 dataC]# python3 test.py -h
-a value of a

Tips:
参数c后面没有冒号,因此 -c 后参数没有被传递。
来源:【九爱网址导航www.fuzhukm.com】
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!