I need to use JS and also i have a python script that i have to use. With print statement JavaScript can use the python output but my python function returns list and integer so print format not useful for this case. For example i wrote a python script which contains function. But this JS code work with print function.
Python Code
import sys
def function(a,b):
variable = a+b
return variable
function(sys.argv[1],sys.argv[2])
JS Code
const express = require('express')
const {spawn} = require('child_process');
const app = express()
const port = 3000
app.get('/', (req, res) => {
var dataToSend;
// spawn new child process to call the python script
const python = spawn('python', ['script2.py','num' ,'python']);
// collect data from script
python.stdout.on('data', function (data) {
console.log('Pipe data from python script ...');
dataToSend = data.toString();
console.log(dataToSend)
});
// in close event we are sure that stream from child process is closed
python.on('close', (code) => {
// send data to browser
res.send(dataToSend)
});
})
app.listen(port, () => console.log(`Example app listening on port
${port}!`))
Is there a way that use the python function returns use on JS as arg1,arg2,arg3