Neurohazard
暮雲煙月,皓首窮經;森羅萬象,如是我聞。

在 Python 中调用 JavaScript

wpadmin~July 29, 2019 /System Management

在 Python 中调用 JavaScript

正文

依赖

# 依赖
# Python 3 安装
pip install PyExecJS
# Python 2 安装
pip install pyexecjs

示例

# 示例1
import execjs

jsFunc = '''
    function add(x,y){
    return x+y;
    }
'''
jscontext = execjs.compile(jsFunc)
a = jscontext.call('add',3,5)
print(a)
# 可识别字符串,元组,字典,列表等

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.