임베디드 | 라즈베리파이 | ARM | 리눅스 | Qt | 딥러닝

nodejs 에서 python-shell 을 사용하는 방법은 매우 간단하다.

npm 설치해주고 관련 문서 그대로 실행해주면 끝!


var PythonShell = require('python-shell');

 

var options = { 

mode: 'text ',

pythonOptions: ['-u'],

scriptPath: './', 

};



startpython = PythonShell('u21.py');


startpython.end(function (err) {

if (err) return done(err);

console.log('finished');

}); 


sendpython.send('hello world!');


startpython = new PythonShell('u21.py', options);

startpython = PythonShell.run('u21.py', function (err) {

if (err) throw err;

console.log('finished');

});


pyshell = new PythonShell('u21.py',{scriptPath:"./", pythonOptions: ['-u']});


PythonShell.run('u21.py', options, function (err, results) {

if (err) throw err;

// results is an array consisting of messages collected during execution 

console.log('results: %j', results);

});


PythonShell.on('message', function (message) {

// received a message sent from the Python script (a simple "print" statement) 

// console.log(message);


});