使用node.js并试图让节点运行python-shell,计算一个值,然后返回computePython()的答案作为关键结果的对象。应该返回到另一个函数的函数内的回调
如何获取消息以返回结果:FutureValue()? 的console.log(消息)。在(“信息”中的作品..
function computePython(){
return {
result: FutureValue() // I want message from FutureValue() to show up here
};
}
function FutureValue(){
var rate = 0.05;
var nper = 10;
var pmt = 100;
var pv = 100;
var result;
new PythonShell('future_value.py', jsc(options, {
args: [rate, nper, pmt, pv]
}))
.on('message', function (message) {
console.log(message); //works
return message;
});
}
我想你应该使用[Promise](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise)。 –