python中运行js代码—js2py

import js2py

# 实例化一个执行js的环境对象
context_js_obj = js2py.EvalJs()
js_str = """
    function A(a,b){
        return a+b
    }
"""
# 传递js_str,执行js
context_js_obj.execute(js_str)

result = context_js_obj.A(1, 2)
print(result)

# 创建变量
context_js_obj.num = 30
print(context_js_obj.num)

 

posted @ 2019-08-03 00:12  Mr_Smith  阅读(1264)  评论(0编辑  收藏  举报