我想从 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)