简单地用shell调用python

  • 两个文件

test.sh

python /.../test.py

test.py

print('test')

用shell传参数调用python

  • 两个文件

test.sh

a=1
b=2
python /.../test.py $a $b

test.py

import sys
def main(x,y):
    print ('x:',x)
    print ('y:',y)

main(sys.argv[1],sys.argv[2])
文件 test.sh test.py
变量1 a sys.argv[1]
变量2 b sys.argv[2]