美文网首页
2022-08-18 node 与 python 交互

2022-08-18 node 与 python 交互

作者: 忙于未来的民工 | 来源:发表于2022-08-18 15:17 被阅读0次

node与python交互,可以使用 python-shell 。

用法:

node中:

let  { PythonShell } = require('python-shell')

let options = {

    // mode: 'text',

    // pythonPath: 'path/to/python', // 脚本目录

    // pythonOptions: ['-u'], // get print results in real-time

    // scriptPath: 'path/to/my/scripts',

    args: [`value`] // 传参
}

// speesh.py 脚本名字
PythonShell.run('speesh.py', options, function (err, res) {

    if (err) throw err;

    console.log('finished', res); // finished [ "['speesh.py', 'value']"
]

});

python:

import sys
// 打印参数
print(sys.argv)

更多用法:
https://github.com/extrabacon/python-shell

相关文章

网友评论

      本文标题:2022-08-18 node 与 python 交互

      本文链接:https://www.haomeiwen.com/subject/bmpegrtx.html