PyV8 V8 的 Python 封装

我要开发同款
匿名用户2014年04月15日
38阅读
开发技术Python
所属分类Web应用开发、浏览器/JS引擎
授权协议Apache

作品详情

PyV8是V8引擎的Python语言封装,这是Python和JavaScript对象之间的桥,支持在Python脚本中调用V8引擎。

>>> import PyV8>>> ctxt = PyV8.JSContext()          # create a context with an implicit global object>>> ctxt.enter()                     # enter the context (also support with statement)>>> ctxt.eval("1+2")                 # evalute the javascript expression3                                    # return a native python int>>> class Global(PyV8.JSClass):      # define a compatible javascript class...   def hello(self):               # define a method...     print "Hello World"    ...>>> ctxt2 = PyV8.JSContext(Global()) # create another context with the global object>>> ctxt2.enter()                    >>> ctxt2.eval("hello()")            # call the global object from javascriptHello World                          # the output from python script

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论