linux中如何用shell命令调用python函数

创建两个测试文件 Test_shell.sh 、Test_python.py

Test_shell.sh

#!/bin/sh

python -c 'import Test_shell;Test_shell.test()'

Test_python.py

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import commands

def test():
  print "ok"  #缩进
  return   #函数里面要缩进

chmod +x Test_shell.sh

./Test_shell.sh

运行结果ok

猜你喜欢

转载自blog.csdn.net/rong11417/article/details/87916494