[英]how can modify python script var with node.js?
// 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以及求和公式
//我想将num1的值更改为5或6 ...使用node.js可以帮助我吗?
您有两种可能性:
1)在运行python脚本之前编辑文件:将文件加载到node中,进行解析,然后覆盖该值。
2)从运行的python脚本中调用节点JS路由,并使节点从该路由返回新值。
希望这可以帮助 !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.