{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "# A Python kernel backed by Pyodide\n", "\n", "![](https://raw.githubusercontent.com/pyodide/pyodide/master/docs/_static/img/pyodide-logo.png)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "trusted": true }, "outputs": [], "source": [ "import pyodide_kernel\n", "pyodide_kernel.__version__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Simple code execution" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "trusted": true }, "outputs": [], "source": [ "a = 3" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "trusted": true }, "outputs": [], "source": [ "a" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "trusted": true }, "outputs": [], "source": [ "b = 89\n", "\n", "def sq(x):\n", " return x * x\n", "\n", "sq(b)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "trusted": true }, "outputs": [], "source": [ "print" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "# Redirected streams" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "trusted": true }, "outputs": [], "source": [ "import sys\n", "\n", "print(\"Error !!\", file=sys.stderr)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Error handling" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true, "trusted": true }, "outputs": [], "source": [ "\"Hello\"\n", "\n", "def dummy_function():\n", " import missing_module" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "trusted": true }, "outputs": [], "source": [ "dummy_function()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Code completion" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### press `tab` to see what is available in `sys` module" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "trusted": true }, "outputs": [], "source": [ "from sys import " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Code inspection" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### using the question mark" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "trusted": true }, "outputs": [], "source": [ "?print" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### by pressing `shift+tab`" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "trusted": true }, "outputs": [], "source": [ "print(" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Input support" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "trusted": true }, "outputs": [], "source": [ "name = await input('Enter your name: ')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "trusted": true }, "outputs": [], "source": [ "'Hello, ' + name" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Rich representation" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "trusted": true }, "outputs": [], "source": [ "from IPython.display import display, Markdown, HTML, JSON, Latex" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## HTML" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "trusted": true }, "outputs": [], "source": [ "print('Before display')\n", "\n", "s = '