Python 轉 JavaScript 代碼:PythonJS

jopen 10年前發布 | 58K 次閱讀 PythonJS Python開發

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</pre></code>

Example Projects

https://github.com/PythonJS/pythonjs-demo-server-nodejs

https://github.com/PythonJS/pypubjs


項目主頁:http://www.baiduhome.net/lib/view/home/1402276068556

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!