I want to get return value of tmp.py in tmp.js. How can I solve this?
def function():
return 'tmp'
const {PythonShell} = require('python-shell');
PythonShell.run('tmp.py')
A file does not have a 'return' value. A function however, does.
Either:
modify your tmp.py such that the desired function gets called
def function()
return 'tmp'
if __name__ == '__main__':
var = function()
print(var)
or directly run the code in the shell
const {PythonShell} = require('python-shell');
PythonShell.run('import tmp')
PythonShell.run('print(tmp.function())')
returnvalue. A function does. Modifiy your tmp.py such that it includes the call to the function:if __name__ == '__main__': function()