我有用nodeJS配置的python-shell。 我试图通过调用回调函数从pythonShell返回。 回调函数能够成功地控制从pythonShell记录结果,但是,我无法返回它。我相信这是因为PythonShell.run不支持返回。
// Python Invocation
exports.find = function (searchterm) {
var PythonShell = require('python-shell');
function callback (err, results) {
console.log(results); //Exhibit A (logs successfully)
}
// PythonShell does not support return
PythonShell.run('findAnswer.py', callback);
//How do I return Exhibit A?
};
有任何关于此的提示将不胜感激
由于
答案 0 :(得分:0)
您可以修改您的功能,如下所示
exports.find = function (searchterm, callback) {
var PythonShell = require('python-shell');
// PythonShell does not support return
PythonShell.run('findAnswer.py', callback);
};
并使用如下:
var finds = require('modulename').find;
finds('search term', function(err, results){
//do anything with results here
});