运行 Python 来自 Bash 的函数

Running Python Function from Bash

我在 configure.py 中创建了一个函数 configure_propeties(),我正尝试使用以下命令在 bash 脚本中调用它:

python3.6 -c "import configure; print configure.configure_properties()"

执行 bash 脚本后,我收到以下警告:

warning

脚本和 configure.py 都在同一目录中。不确定发生了什么,导入似乎没有失败。有人以前见过这个问题吗?

print 使用括号,这是 Python 3

所必需的

print "blabla" 只在python 2 中可用,python 3 你必须使用括号print("blabla"),最好设置你的python 脚本在 .py 文件中,只需确保 python 可执行文件在您的 PATH 环境变量中,然后添加到您的脚本

python3 path/to/the/python_script.py

在 bash 脚本文件 bashFile.sh 中,输入:

#!/bin/bash
python3 path/to/the/python_script.py

然后你可以执行你的 bash 文件 bashFile.sh :

bash path/to/bashFile.sh