An open API service indexing awesome lists of open source software.

https://github.com/python-ninja-hebi/pyscript-puzzles

Some small programs with pyscript
https://github.com/python-ninja-hebi/pyscript-puzzles

html javascript pyscript python

Last synced: 10 months ago
JSON representation

Some small programs with pyscript

Awesome Lists containing this project

README

          

{
"cells": [
{
"cell_type": "markdown",
"id": "2f29d06e-aa35-446e-b8b8-e0c65f641d5f",
"metadata": {},
"source": [
"# pyscript puzzle"
]
},
{
"cell_type": "markdown",
"id": "9f64b26e-aa65-4c95-b418-79d91c2153bd",
"metadata": {},
"source": [
"Some small programs with pyscript (https://pyscript.net)"
]
},
{
"cell_type": "markdown",
"id": "3bfc9411-255a-49a1-81fb-75eaa77f8d50",
"metadata": {},
"source": [
"## #2"
]
},
{
"cell_type": "markdown",
"id": "4ea978bc-e7d0-4f1a-8f14-a16f67eb256a",
"metadata": {},
"source": [
"Sometimes you need a nice formated **table** in **PyScript**."
]
},
{
"cell_type": "markdown",
"id": "0e068dc7-fa75-4eb0-ba35-f970f2bca9f4",
"metadata": {},
"source": [
"**Task:**\n",
"\n",
"Make a table with Bootstrap.js."
]
},
{
"cell_type": "markdown",
"id": "add1d664-fb32-48a7-9b34-289120c34d8c",
"metadata": {},
"source": [
"













"
]
},
{
"cell_type": "markdown",
"id": "4d84bdad-a077-41aa-8f67-31933563e53c",
"metadata": {},
"source": [
"**Solution**\n",
"\n",
"You can use **Bootstrap** in Python like you do in JavaScript."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3b9427b8-1621-415d-938a-a249ca6c7999",
"metadata": {},
"outputs": [],
"source": [
"\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" puzzle #4 bootstrap table \n",
" \n",
" \n",
" \n",
" Name\n",
" description\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"\n",
" \n",
"import js\n",
"import inspect\n",
"\n",
"table = js.document.getElementById('content')\n",
"\n",
"for i in inspect.getmembers(js):\n",
" row = js.document.createElement('tr')\n",
" object_name = js.document.createElement('td')\n",
" description = js.document.createElement('td')\n",
"\n",
" object_name.innerText = i[0]\n",
" description.innerText = str(i[1])\n",
"\n",
" row.append(object_name)\n",
" row.append(description)\n",
"\n",
" table.appendChild(row)\n",
" \n",
" \n",
""
]
},
{
"cell_type": "markdown",
"id": "d110134e-43ed-4c48-bdcb-e148a6b36320",
"metadata": {},
"source": [
"## #1"
]
},
{
"cell_type": "markdown",
"id": "66736628-c2cd-4641-9fc3-1a19d2d73612",
"metadata": {},
"source": [
"In **PyScript** you can use **JavaScript programm objects** with the Python module **js**."
]
},
{
"cell_type": "markdown",
"id": "c5e14fab-8c38-4e6c-81ee-29fcd418aff7",
"metadata": {},
"source": [
"**Task:**\n",
"\n",
"List all JavaScript programm objects with python."
]
},
{
"cell_type": "markdown",
"id": "8c5a0050-1164-46f7-830a-89867f477994",
"metadata": {},
"source": [
"













"
]
},
{
"cell_type": "markdown",
"id": "bdc0905c-0342-458a-9b1e-4b914bb1276e",
"metadata": {},
"source": [
"**Solution**\n",
"\n",
"Use Python module **inspect**. It works also with JavaScript."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9741f583-2ab6-405b-a39b-cd1b74618b89",
"metadata": {},
"outputs": [],
"source": [
"\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" puzzle #1 Inspect js\n",
"

\n",
"\n",
" \n",
"import js\n",
"import inspect\n",
"\n",
"for i in inspect.getmembers(js):\n",
" PyScript.write('content',f'

{i[0]} {i[1]}

', append=True)\n",
" \n",
" \n",
""
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}