// node.js文件包含
var PythonShell = require('python-shell',{mode:'binary'});
var pyshell = new PythonShell('my_script.py');
// sends a message to the Python script via stdin
pyshell.send('hello');
pyshell.on('message', function (message) {
// received a message sent from the Python script (a simple "print" statement)
console.log(message);
});
// end the input stream and allow the process to exit
pyshell.end(function (err) {
if (err) throw err;
console.log('finished');
});
// my_script.py文件
# This program adds two numbers
num1 = 1.5
num2 = 6.3
# Add two numbers
sum = float(num1) + float(num2)
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
//在python文件中,你会看到num1和num 2以及sum公式
//我想将num1值更改为5或6 ...使用node.js可以帮助我吗?
答案 0 :(得分:0)
您有两种可能性:
1)在运行python脚本之前编辑文件:在节点中加载文件,解析它,并覆盖该值。
2)从运行的python脚本调用节点JS路由,make节点从此路由返回新值。
希望这有帮助!