执行python脚本的时候,想给main方法传入参数的例子
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author(s): xili
# @Created: 2020/6/30
import sys
if __name__ == '__main__':
arg1 = sys.argv[1]
arg2 = sys.argv[2]
print(arg1)
print(arg2)
执行结果:
[root@xili]# python test1.py 1 2
1
2