我想从JavaScript代码中调用一个Python函数,因为在JavaScript中没有其他方法可以做到我想要的。这种情况可能吗?你能否修改下面的片段使其工作吗?
JavaScript代码:
var tag = document.getElementsByTagName("p")[0];
text = tag.innerHTML;
// Here I would like to call the Python interpreter with Python function
arrOfStrings = openSomehowPythonInterpreter("~/pythoncode.py", "processParagraph(text)");
~/pythoncode.py
包含使用高级库编写的函数,这些库在JavaScript中没有容易编写的等效物:
import nltk # is not in JavaScript
def processParagraph(text):
...
nltk calls
...
return lst # returns a list of strings (will be converted to JavaScript array)