安装方法:
pip install -e git://github.com/brokenseal/PyV8-OS-X#egg=pyv8
github项目:
https://github.com/brokenseal/PyV8-OS-X#egg=pyv8
https://github.com/emmetio/pyv8-binaries
# -*- coding: utf-8 -*- # @File : pyv8_demo.py # @Date : 2018-05-29 from pyv8 import PyV8 ctxt = PyV8.JSContext() ctxt.enter() # 函数 func = ctxt.eval(""" (function(){ function hello(){ return "Hello world."; } return hello(); }) """) print func() # Hello world. # 变量 ctxt.eval(""" var_ex1 = 1; var_ex2 = 1.0; var_ex3 = "test"; var_ex4 = true; """) vars = ctxt.locals print vars.var_ex1 # 1 # 传入参数 ctxt.locals.test = 12 print int(ctxt.eval("test")) # 12