看到的一个有趣的 Open Source 项目(Brython), 虽然我觉得没什么实用性~ XD

不过, 既然是蛇年, 就让 浏览器 也 蛇化 吧~

Brython 的说明:

Brython的目标是用Python取代JavaScript,使Python成为web浏览器的脚本语言。

Brython – 在浏览器用 Python 取代 JavaScript

此项目载入一个 js 文件, 然后就可以用 Python 语法来操作 DOM、AJAX… 等等的事情. (写在

Brython Syntax 笔记

Brython Syntax 说明: Brython Syntax

link1 = A(\'Brython\', href=\'http://www.brython.info\')
link2 = A(B(\'Python\'), href=\'http://www.python.org\')

建立 a 并 附加属性

link = A()
link <= B(\'connexion\')
link.href = \'http://example.com\'

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 None

text/python 写法范例


Brython 相关 Library (库)

库的套件可见: Brython – Compiling and running

这边有很多必须的 Library, 在这边列一些应用类的.

  • py2js.js : does the conversion between the tokens and the Javascript code
  • py_dom.js : interaction with the HTML document (DOM)
  • py_ajax.js : Ajax implementation
  • py_local_storage.js : implementation of the HTML5 local storage
  • py_svg.py : SVG support (vector graphics)

by Tsung under CC-by-sa