{"id":23949713,"url":"https://github.com/liaplayground/pythonprogramming","last_synced_at":"2025-04-22T20:10:55.325Z","repository":{"id":133197667,"uuid":"429472943","full_name":"LiaPlayground/PythonProgramming","owner":"LiaPlayground","description":"Some examples on how to use Python in LiaScript","archived":false,"fork":false,"pushed_at":"2021-11-18T16:45:57.000Z","size":6,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T18:22:56.062Z","etag":null,"topics":["liascript","liascript-course","liascript-template","oer","programming","python"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LiaPlayground.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-18T15:03:16.000Z","updated_at":"2024-07-04T18:00:09.000Z","dependencies_parsed_at":"2023-03-22T23:15:40.426Z","dependency_job_id":null,"html_url":"https://github.com/LiaPlayground/PythonProgramming","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaPlayground%2FPythonProgramming","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaPlayground%2FPythonProgramming/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaPlayground%2FPythonProgramming/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaPlayground%2FPythonProgramming/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LiaPlayground","download_url":"https://codeload.github.com/LiaPlayground/PythonProgramming/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250316042,"owners_count":21410475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["liascript","liascript-course","liascript-template","oer","programming","python"],"created_at":"2025-01-06T11:50:09.079Z","updated_at":"2025-04-22T20:10:55.320Z","avatar_url":"https://github.com/LiaPlayground.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\nauthor:   André Dietrich\n\nemail:    LiaScript@web.de\n\nversion:  0.0.1\n\nlanguage: en\n\nnarrator: US English Female\n\ncomment:  A demo on Python and LiaScript.\n\nicon:     https://pbs.twimg.com/profile_images/1388100423094087681/08Nvxq--_400x400.jpg\n\nimport:   https://github.com/LiaTemplates/Pyodide/blob/0.1.4/README.md\n          https://github.com/LiaScript/CodeRunner/blob/master/README.md\n\n@@ can also be replaced by @Pyodide.eval\n\n@eval:  @LIA.eval(`[\"main.py\"]`, `python -m compileall .`, `python main.pyc`)\n\n--\u003e\n\n[![LiaScript](https://raw.githubusercontent.com/LiaScript/LiaScript/master/badges/course.svg)](https://LiaScript.github.io/course/?https://github.com/LiaPlayground/PythonProgramming/blob/main/README.md)\n\n# Python Programming\n\n\nIf you want to teach Python or at least run some Python snippets within your\ncourse, we currently recommend two different packages for LiaScript.\n\n1. [Pyodide](https://github.com/LiaTemplates/Pyodide)\n2. [CodeRunner](https://github.com/liascript/coderunner)\n\nWhat is the difference? Pyodide will load all libraries into your browser and\nexecute it locally, while CodeRunner will compile and execute the code on a\nforeign server. The first project might cover only a reduced set of libraries,\nbut it scales and adds plotting functionality, in contrast to the second one.\nIn CodeRunner, plots can at the moment only be generated with R.\n\n## 1. Pyodide\n\n\n\u003e To use this functionality, you will have to import:\n\u003e\n\u003e ``` html\n\u003e \u003c!--\n\u003e ...\n\u003e import: https://github.com/LiaTemplates/Pyodide/blob/0.1.4/README.md\n\u003e\n\u003e --\u003e\n\u003e ```\n\u003e\n\u003e Afterwards you can attach the macro `@Pyodide.eval` to every Python-Code\n\u003e snippet.\n\u003e\n\u003e **Note: All scripts are executed in one global environment**\n\n### Examples\n\n``` python\nimport sys\n\nfor i in range(5):\n\tprint(\"Hello\", 'World #', i)\n\nsys.version\n```\n@Pyodide.eval\n\n\n---\n\n\u003e Currently you can only plot one image, but this is shown within the terminal\n\u003e and also stored persitently. Thus, you can switch between different versions\n\u003e of your code and the resulting images will change too.\n\n``` python\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nt = np.arange(0.0, 2.0, 0.01)\ns = np.sin(2 * np.pi * t)\n\nfig, ax = plt.subplots()\nax.plot(t, s)\n\nax.grid(True, linestyle='-.')\nax.tick_params(labelcolor='r', labelsize='medium', width=3)\n\nplt.show()\n\nplot(fig) # \u003c- this is required to plot the fig also on the LiaScript canvas\n```\n@Pyodide.eval\n\n\u003e **NOTE:** You can resize the terminal and you can click onto the image to\n\u003e enlarge it. The additional loading of libraries is only required once, then\n\u003e they are stored locally...\n\n## 2. LiaScript Code-Runner\n\n\u003e This allows, to run and execute your code on a real\n\u003e\n\u003e ```` markdown\n\u003e \u003c!--\n\u003e ...\n\u003e import: https://github.com/LiaScript/CodeRunner/blob/master/README.md\n\u003e\n\u003e --\u003e\n\u003e\n\u003e # ...\n\u003e\n\u003e ```python\n\u003e for i in range(10):\n\u003e   print \"Hallo Welt\", i\n\u003e ```\n\u003e @LIA.eval(`[\"main.py\"]`, `python -m compileall .`, `python main.pyc`)\n\u003e ````\n\u003e\n\u003e Afterwards you can attach the macro `@LIA.eval` to every Python-Code\n\u003e snippet.\n\u003e\n\u003e The `@LIA.eval` macro might look a bit cryptic, but it actually consists\n\u003e of three steps.\n\u003e\n\u003e 1. A list of filenames, if you use require more than one files for your\n\u003e    project, then these have to be defined in order. A project can consist of\n\u003e    multiple code-snippets attached to each other\n\u003e 2. A compilation command\n\u003e 3. A execution command\n\n\n### Example\n\n\n```python\nfor i in range(10):\n  print \"Hallo Welt\", i\n```\n@LIA.eval(`[\"main.py\"]`, `python -m compileall .`, `python main.pyc`)\n\n\n## Best Practice\n\n\nIf you you have a couple of code-snippets and you do not want to add always the\nsame complex macro, which might eventually change in the future. The best way is\nto define a custom macro, which defines the macro with all parameters. You can\nmodify this in the future, just by changing the macro-definition an also the\nimport. It is thus not required to change every macro separately:\n\n```` markdown\n\u003c!--\n...\n\nimport:   https://github.com/LiaTemplates/Pyodide/blob/0.1.4/README.md\n          https://github.com/LiaScript/CodeRunner/blob/master/README.md\n\n@@ can also be replaced by @Pyodide.eval\n@eval:  @LIA.eval(`[\"main.py\"]`, `python -m compileall .`, `python main.pyc`)\n\n--\u003e\n\n# ...\n\n```python\nfor i in range(10):\n  print \"Hallo Welt\", i\n```\n@eval\n\n\n```python\nfor i in range(10):\n  print \"Hello World\", i\n```\n@eval\n````\n\n\n---\n\n\n```python\nfor i in range(10):\n  print \"Hallo Welt\", i\n```\n@eval\n\n\n```python\nfor i in range(10):\n  print \"Hello World\", i\n```\n@eval\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliaplayground%2Fpythonprogramming","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliaplayground%2Fpythonprogramming","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliaplayground%2Fpythonprogramming/lists"}