1

I have a js file with:

function hi (){
console.log("Hello world!");
return 'hello';
}

And I want to call this function from my python code. I'm using the naked lib, so I run something like this:

from Naked.toolshed.shell import execute_js
response = execute_js('node.js')
print response

But I want to run this specific method hi(), not execute the script 'Node.js' (because it does nothing by itself). I also wan't to get the returned value.

I'm able to use another lib if necessary.

rriccilopes
  • 399
  • 2
  • 10
  • 1
    Why don't you make a script that _only_ calls `hi()` in your other one, then run that with execute_js? – byxor Aug 31 '16 at 15:32
  • It's a good approach.. I didn't think about it. But to get the returned value I would need to write it into a file and read it in python, right? – rriccilopes Aug 31 '16 at 15:36
  • I would assume so, I've never used the library before. It would get out of control though if you wanted to call more methods. Perhaps [this library](https://pypi.python.org/pypi/PyExecJS) might suit your needs. – byxor Aug 31 '16 at 15:38
  • I've tried this lib. But I can call the function from the file? I saw I can compile a code (just like the example) and run it.. but I need to get this function from a js file... I would need to read this file as string and give it as parameter? – rriccilopes Aug 31 '16 at 15:42
  • Your question has nothing to do with Node.js... That's plain Javascript – OneCricketeer Aug 31 '16 at 15:43
  • It's similar to this question.. but his question is embracing. I want to call a js function from a js file and get the output from this function in python. I've tried the suggestions from this question, but didn't work for me. – rriccilopes Sep 05 '16 at 13:53

0 Answers0