0

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')
1
  • 2
    A file does not have a return value. A function does. Modifiy your tmp.py such that it includes the call to the function: if __name__ == '__main__': function() Commented Jul 3, 2019 at 9:21

1 Answer 1

1

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())')
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.