PythonShell.run公司在结果nodejs中返回null

2024-09-28 22:30:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过PythonShell在nodejs中运行python脚本。但我的结果是空的。我不知道python脚本是返回空值还是nodejs代码中有问题。你知道吗

节点代码

var PythonShell = require('python-shell');
////options for python-shell
PyShellOptions={
mode: 'JSON',
pythonOptions: ['-u'],
scriptPath: 'F:/University/Final Year/FYP/From Shafeeq/ECG-Diagnosis (Python)',//python scripts folder
args: [signal_file,sample_rate,user.meta.age,user.meta.gender,user.meta.height,user.meta.weight]
};

    PythonShell.run('main.py', PyShellOptions, function (err, results) {
        console.log(err);
        if (err) {
             console.log(err.message)
        }
        // results is an array consisting of messages collected during execution
        console.log('results: %j', results);
}

Python代码

print(json_content)

Tags: 代码脚本log节点varnodejsshellresults