我想导出名为completed的变量,以便使用pythonshell.run函数。有什么建议吗?这是我的密码。
python代码
# test.py
import sys
def hello(a,b):
print("hello and that's your sum:", a + b)
if __name__ == "__main__":
a = int(sys.argv[1])
b = int(sys.argv[2])
hello(a, b)
javascript代码
let {PythonShell} = require('python-shell')
let options = {
mode: 'text',
pythonOptions: ['-u'], // get print results in real-time
args: [1414, 2323]
};
PythonShell.run('./photos/filterPhoto/test.py', options, function (err, results) {
if (err) throw err;
const completed = results;
///results: ["hello and that's your sum: 3737"]
});
console.log(completed)
Error : ReferenceError: completed is not defined
1条答案
按热度按时间0kjbasz61#
尝试使用jspybridge/pythonia调用python脚本:
通过es6导入:
或通过commonjs导入: