1

There is a python module 'python-shell', but it calls the whole python program what if I just want to call a specific function of python from nodejs, is there any way ?

Thank you !

  • Please read the following article on how to ask a good question: https://stackoverflow.com/help/how-to-ask – Nick Sep 11 '19 at 11:08
  • Please checkout this answer for your question I hope this helps: https://stackoverflow.com/a/23452742/4439699 – Ruchir Sep 11 '19 at 11:08
  • Ruchir Thank you, but child_process is used to run the whole python script not an individual function. –  Sep 11 '19 at 11:12
  • var process = spawn('python',["./hello.py", req.query.firstname, req.query.lastname] ); store that function to hello.py in order to test it so you may have a module to work with – Ruchir Sep 11 '19 at 11:19

1 Answers1

0

Write a short python program calling your function, and run it using the child_process module as shown in this thread. You'll be able to get standard output back.

Ryan Fleck
  • 158
  • 7
  • Yes thanks, but is there another efficient way to do it , because here I need to create different python file for different functionality. –  Sep 11 '19 at 11:15
  • 1
    You could pass the function name as an argument to the python program, but as far as I know, there is no way to call a specific python function from NodeJS. – Ryan Fleck Sep 11 '19 at 11:16