Python 转 JavaScript 代码:PythonJS
jopen
11年前
PythonJS 是一个用 Python 写的转换器,用来将 Python 代码转成快速的 JavaScript, Dart, Coffee,和 Lua 。它可以与常规的Python运行,或完全自托管的使用Empythoned的NodeJS内。PythonJS设计成快速并且易于与现有的JavaScript代码集成。
安装
npm install python-js
NodeJS Quick Example
var pythonjs = require('python-js'); var pycode = "a = []; a.append('hello'); a.append('world'); print(a)"; var jscode = pythonjs.translator.to_javascript( pycode ); eval( pythonjs.runtime.javascript + jscode );
JavaScript API
var pythonjs, output; pythonjs = require('python-js'); output = pythonjs.translator.to_javascript( input ); output = pythonjs.translator.to_javascript_module( input ); output = pythonjs.translator.to_dart( input ); output = pythonjs.translator.to_coffee( input ); output = pythonjs.translator.to_lua( input ); pythonjs.runtime.javascript // runtime required by translator output
Example Projects
https://github.com/PythonJS/pythonjs-demo-server-nodejs
https://github.com/PythonJS/pypubjs