首页 > 解决方案 > PythonShell.run 在结果 nodejs 中返回 null

问题描述

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

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)

标签: pythonnode.js

解决方案


推荐阅读