python编译javascript_Js2Py - 把js代码翻译成python代码。也让你可以在python环境里运行js代码。...

Pure Python JavaScript Translator/InterpreterEverything is done in 100% pure Python so it's extremely easy to install and use. Supports Python 2 & 3. Full support for ECMAScript 5.1, ECMA 6 support ...
摘要由CSDN通过智能技术生成

68747470733a2f2f7472617669732d63692e6f72672f50696f74724461626b6f77736b692f4a733250792e7376673f6272616e63683d6d617374657268747470733a2f2f706570792e746563682f62616467652f6a733270792f6d6f6e7468

Pure Python JavaScript Translator/Interpreter

Everything is done in 100% pure Python so it's extremely easy to install and use. Supports Python 2 & 3. Full support for ECMAScript 5.1, ECMA 6 support is still experimental.

Simple Example:

>>> import js2py

>>> js2py.eval_js('console.log( "Hello World!" )')

'Hello World!'

>>> add = js2py.eval_js('function add(a, b) {return a + b}')

>>> add(1, 2) + 3

6

>>> add.constructor

function Function() { [python code] }

>>> js2py.require('underscore')

'function _(obj) { [python code] }'

You can also import a big number of node modules as if they were written in Python! For example, here we import a pure JS library crypto-js:

>>> CryptoJS = js2py.require('crypto-js')

>>> data = [{'id': 1}, {'id': 2}]

>>> JSON = js2py.eval_js('JSON')

>>> ciphertext = CryptoJS.AES.encrypt(JSON.stringify(data), 'secret key 123')

>>> bytes = CryptoJS.AES.decrypt(ciphertext.toString(), 'secret key 123')

>>> decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8)).to_list()

>>> decryptedData

[{u'id': 1}, {u'id': 2}]

Now also supports JavaScript 6 (still experimental):

>>> js2py.eval

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值