I'm using this python-shell package and very new to the world of python and nodejs.
I'm looking to pass values to a python script below.
script.py
my_name = [0]
print("Hello and welcome " + my_name + "!")
I would like to pass the arg of "Bruce Wayne" below and have the above script.py receive it in the my_name variable.
pythonShell.js
var PythonShell = require('python-shell');
var options = {
mode: 'text',
pythonPath: '/usr/bin/python',
pythonOptions: ['-u'],
// make sure you use an absolute path for scriptPath
scriptPath: '/home/username/Test_Project/Python_Script_dir',
args: ['Bruce Wayne']
};
PythonShell.run('script.py', options, function (err, results) {
if (err) throw err;
// results is an array consisting of messages collected during execution
console.log('results: %j', results);
});