pytest.py
from sys import argv
def f1():
print('this is f1.')
if __name__ == '__main__':
a = 'abc'
b = 'xyz'
c = a+b
d = 'abc''xyz'
print(c)
print(d)
print("argv[0]", argv[0])
for i in argv:
print(i)
#if len(argv)>1:
# print('argv1', argv[1])
input()
# /bin/bash
# shell调用python脚本,并且向python脚本传递参数
a=100
b="ZhongGuo"
python pytest.py $a $b
# 使用shell调用python中的函数
python -c 'import pytest; print pytest.f1()' #还有问题!
脚本输出结果
abcxyz
abcxyz
argv[0] pytest.py
pytest.py
100
ZhongGuo