猿问

从JavaScript代码调用Python函数

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


手掌心
浏览 3930回答 3
3回答
随时随地看视频慕课网APP
我要回答