JavaScript 可以使用 Node.js 的 child_process
模块来调用 Python 代码。
例如,你可以使用 child_process.spawn
方法来调用 Python 脚本:
const { spawn } = require('child_process');
const pythonProcess = spawn('python', ['path/to/your/python/script.py', arg1, arg2, ...]);
pythonProcess.stdout.on('data', (data) => {
// Do something with the data returned from python script
});
你也可以使用 child_process.exec
或 child_process.execFile
方法来调用 Python 脚本。
注意,在调用 Python 代码之前,你需要确保已在你的系统中安装了 Python 和所需的库。