We can program, right now, web pages using Python!
Imagine my surprise. While studying the python sources in live-py-plugin/plugin/PySrc/code_tracer.py I ran across JS code!
def web_main():
display()
document.getElementById('source').addEventListener('input', display)
Huh? Here is the top-level code:
if __name__ == '__main__':
main()
elif IS_PYODIDE:
web_main()
Googling pyodide yields
this page. From the readme file at the bottom:
The Python scientific stack, compiled to WebAssembly. It provides transparent conversion of objects between Javascript and Python. When inside a browser, this means Python has full access to the Web APIs.
OMG:
WebAssembly is a
web standard and is supported in all major browsers!! From the
MDN page:
QQQ
WebAssembly is a new type of code that can be run in modern web browsers—it is a low-level assembly-like language with a compact binary format that runs with near-native performance and provides languages such as C/C++ with a compilation target so that they can run on the web. It is also designed to run alongside JavaScript, allowing both to work together.
WebAssembly has huge implications for the web platform—it provides a way to run code written in multiple languages on the web at near native speed, with client apps running on the web that previously couldn’t have done so.
QQQ
From the
wikipedia page:
QQQ
WebAssembly is a
web standard that defines a binary format and a corresponding
assembly-like text format for executable
code in
Web pages. It is meant to enable executing code nearly as quickly as running native
machine code. It was envisioned to complement
JavaScript to speed up performance-critical parts of web applications and later on to enable
web development in languages other than JavaScript. WebAssembly does not attempt to replace JavaScript, but to complement it. It is developed at the
World Wide Web Consortium (W3C) with engineers from
Mozilla,
Microsoft,
Google, and
Apple.
QQQ
This looks like the way around the lack of browser support for python.
Edward