在瀏覽器用Python取代JavaScript,Brython 3.2.3 發布,
Brython 設計用于替換網頁上的 JavaScript 腳本語言,它使用 Python 來編寫腳本,并直接在網頁上執行。
Brython 3.2.3 發布,此版本改進了運行 CPython 套件 (tests/unittests/index.html) 的頁面,最初是由 Billy Earney 編寫的。此頁面提供一個系統的方法來在 Python 編譯時檢測 bugs。
另一個重要改進是更好的實現了 execution frames。
下載:Brython3.2.3-20151122-082712.tar.gz。
Brython 的說明:
Brython的目標是用Python取代JavaScript,使Python成為web瀏覽器的腳本語言。
</blockquote>Brython - 在瀏覽器用 Python 取代 JavaScript
此項目載入一個 js 文件, 然后就可以用 Python 語法來操作 DOM、AJAX... 等等的事情. (寫在
<script type="text/python">
里面)
- 項目首頁: Brython - browser python
- Google code: brython - Browser Python
</ul>Brython 使用方式(范例)
說明文件: Brython document,
下述范例取自此篇:
<html> <head> <script src="/brython.js"></script> </head> <body onLoad="brython()"> <script type="text/python"> def echo(): alert(doc["zone"].value) </script> <input id="zone"><button onclick="echo()">clic !</button> </body> </html>
Brython Syntax 筆記
Brython Syntax 說明: Brython Syntax
建立 a link
link1 = A('Brython', ) link2 = A(B('Python'), )建立 a 并 附加屬性
link = A() link <= B('connexion') link.
AJAX
req = ajax() req.on_complete = on_complete req.set_timeout(timeout, err_msg) req.open('POST', url, True) req.set_header('content-type', 'application/x-www-form-urlencoded') req.send(data)Local storage
local_storage['foo'] = 'bar' log(local_storage['foo']) del local_storage['foo'] log(local_storage['foo']) # prints Nonetext/python 寫法范例
<script type='text/python'> def mouse_move(ev): doc["trace"].value = '%s %s' %(ev.x,ev.y)doc["zone"].onmousemove = mouse_move </script> </pre>
Brython 相關 Library (庫)
庫的套件可見: Brython - Compiling and running
這邊有很多必須的 Library, 在這邊列一些應用類的.
py2js.js
: does the conversion between the tokens and the Javascript codepy_dom.js
: interaction with the HTML document (DOM)py_ajax.js
: Ajax implementationpy_local_storage.js
: implementation of the HTML5 local storage- </ul>
py_svg.py
: SVG support (vector graphics)
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!