我使用python-shell
在NodeJs环境中运行python脚本。在
我有以下NodeJs代码:
var PythonShell = require('python-shell');
var command = 'open1';
var comport = 6;
var options = {
scriptPath: 'python/scripts'
};
PythonShell.run('controlLock.py', options, function (err, results) {
if (err) throw err;
console.log('results: %j', results);
});
在执行python controlLock
脚本之前,我需要能够将command和COMPORT变量包含到脚本中(否则它将没有正确的值)。在
下面是controlLock.py
文件
你可以run the python script with arguments。传递给
PythonShell.run()
的options
有一个名为args
的属性,可用于将参数传递给python脚本。然后您可以从python脚本中read these command line arguments,并在需要的地方插入它们。在python-shell
参数python脚本
^{pr2}$相关问题 更多 >
编程相关推荐