python 执行javascript 模块 支持 python3

http://pypi.python.org/pypi/PyExecJS/1.0.2



一个解析javascript的模块,虽然支持python3,但是支持的python3支持的引擎貌似有问题啊。

v8是直支持py2.7哎,暂时空架而已


PyExecJS 1.0.2

Run JavaScript code from Python

Downloads ↓

Run JavaScript code from Python.

PyExecJS is a porting of ExecJS from Ruby. PyExecJS automatically picks the best runtime available to evaluate your JavaScript program, then returns the result to you as a Python object.

A short example:


>>> import execjs
>>> execjs.eval("'red yellow blue'.split(' ')")
['red', 'yellow', 'blue']
>>> ctx = execjs.compile("""
...     function add(x, y) {
...         return x + y;
...     }
... """)
>>> ctx.call("add", 1, 2)
3


Of course, you can pick particular JavaScript runtime by get() function:


>>> default = execjs.get() # the automatically picked runtime
>>> default.eval("1 + 2")
3
>>> jscript = execjs.get("JScript")
>>> jscript.eval("1 + 2")
3
>>> node = execjs.get("Node")
>>> node.eval("1 + 2")
3


If EXECJS_RUNTIME environment variable is specified, PyExecJS pick the JavaScript runtime as a default:


>>> #execjs.get().name # this value is depends on your environment.
>>> os.environ["EXECJS_RUNTIME"] = "Node"
>>> execjs.get().name
'Node.js (V8)'


PyExecJS supports these runtimes:

# Installation

$ pip install PyExecJS

or

$ easy_install PyExecJS

# License

Copyright (c) 2012 Omoto Kenji. Copyright (c) 2011 Sam Stephenson and Josh Peek.

Released under the MIT license. See LICENSE for details.

#Changes 1.0.2 : Python 2.6.x was supported. 1.0.1 : Forgotten shell=True was added to Popen. 1.0.0 : First release.

 
File Type Py Version Uploaded on Size # downloads
PyExecJS-1.0.2.zip (md5) Source   2012-02-04 10KB 63
 

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值