2016-12-07 4 views
0

// Node.jsのファイルはPythonのファイルにあなたがNUM1とNUM 2と和式どのようにnode.jsでpythonスクリプトvarを変更できますか?

// Iを参照してください//

var PythonShell = require('python-shell',{mode:'binary'}); 
var pyshell = new PythonShell('my_script.py'); 

// sends a message to the Python script via stdin 
pyshell.send('hello'); 


pyshell.on('message', function (message) { 
    // received a message sent from the Python script (a simple "print" statement) 
    console.log(message); 
}); 

// end the input stream and allow the process to exit 
pyshell.end(function (err) { 
    if (err) throw err; 
    console.log('finished'); 
}); 

// my_script.pyファイル

# This program adds two numbers 

num1 = 1.5 
num2 = 6.3 

# Add two numbers 
sum = float(num1) + float(num2) 

# Display the sum 
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum)) 

が含まれていますnum1の値を5または6に変更したいと思います... node.jsで助けてくれますか?

1)はPythonスクリプトを実行する前に、ファイルを編集します:ノード内のファイルをロードし、それを解析し、その値を上書き

答えて

0

次の2つの可能性があります。

2)実行中のPythonスクリプトからノードJSルートを呼び出し、ノードがこのルートから新しい値を返すようにします。

希望すると便利です。

関連する問題