You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can you clarify your question? What are you struggling with exactly?
Basically, run will return an instance which you can use to send and receive messages.
varpython=PythonShell.run('script.py',{mode: 'json'});// send a messagepython.send({hello: 'world'});// receive a message from Pythonpython.on('message',function(message){// handle message sent from Python}
On the Python side, you simply read from stdin and write to stdout.
# send a JSON message to nodeprintjson.dumps(obj)
# receive messagesformessageinsys.stdin:
# handle message sent from node
I want to use this example:
PythonShell.run('my_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);
});
Activity
extrabacon commentedon Oct 13, 2015
Simply set options using the second argument, like so:
Olmer1st commentedon Oct 13, 2015
Yes. Ok. But how to transfer message?
extrabacon commentedon Oct 13, 2015
Can you clarify your question? What are you struggling with exactly?
Basically,
runwill return an instance which you can use to send and receive messages.On the Python side, you simply read from stdin and write to stdout.
Olmer1st commentedon Oct 13, 2015
I want to use this example:
PythonShell.run('my_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);
});
this example work only with args.
Almenon commentedon Mar 3, 2018
Still having trouble? If not I'll close this.