{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Brython\n", "[Brython](https://www.brython.info/) is an in-browser runtime for Python supporting a subset of the Python 3.4 API." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(1 + 1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import this" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print({i: str(i) for i in range(10)})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "While it mostly quacks like a Python, Brython can do some tricks with its [`browser` module](https://www.brython.info/static_doc/en/browser.html)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import browser" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "browser.document.write(\"Hi there!\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It even overloads `<=` to provide a simple native tree interface" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from browser.html import *\n", "\n", "t = TABLE()\n", "t <= TR(TH('Number')+TH('Square'))\n", "t <= (TR(TD(i)+TD(i*i)) for i in range(10))\n", "browser.document.body <= t" ] } ], "metadata": { "kernelspec": { "display_name": "Brython (unsafe) — Jyve", "language": "python", "name": "jyve-kyrnel-brython-unsafe" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "ES2015" } }, "nbformat": 4, "nbformat_minor": 2 }