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