发布时间:2022-08-09 文章分类:编程知识 投稿人:王小丽 字号: 默认 | | 超大 打印
python javascript engine
2010-07-10 0:02

1) Python Wrapper for Google V8 Javascript Engine

项目url:http://code.google.com/p/pyv8/

源代码:svn checkout http://pyv8.googlecode.com/svn/trunk/ pyv8-read-only

运行环境:windows,linux

详细使用说明及参考代码:http://zhbmblog.appspot.com/media/agh6aGJtYmxvZ3IMCxIFTWVkaWEY_jYM/PyV8.py

01 import PyV8

02 ctxt = PyV8.JSContext() # create a context with an implicit global object

03 ctxt.enter() # enter the context (also support with statement)

04 ctxt.eval("1+2") # evalute the javascript expression

05 3 # return a native python int

06

07 class Global(PyV8.JSClass): # define a compatible javascript class

08 def hello(self): # define a method

09 print "Hello World"

10

11 ctxt2 = PyV8.JSContext(Global()) # create another context with the global object

12 ctxt2.enter()

13 ctxt2.eval("hello()") # call the global object from javascript

14 Hello World # the output from python script

2)python-spidermonkey

项目url:http://code.google.com/p/python-spidermonkey/

源代码:svn checkout http://python-spidermonkey.googlecode.com/svn/trunk/ python-spidermonkey-read-only

运行环境:OS X,64-bit Ubuntu Linux