python有个库PyExecJS
安装:
$ pip install PyExecJS
或者
$ easy_install PyExecJS
调用:
>>> import execjs
>>> execjs.eval("'red yellow blue'.split(' ')")
['red', 'yellow', 'blue']
>>> ctx = execjs.compile("""
... function add(x, y) {
... return x + y;
... }
... """)
>>> ctx.call("add", 1, 2)
3
更多用法参考:https://pypi.python.org/pypi/PyExecJS
(转自 https://wuwawuwa.cn)