From 71f47bb22368b6a47d899fc65271e92efec61bf1 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Thu, 1 Oct 2020 20:51:23 +0800 Subject: [PATCH 01/15] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 12a9352c..0e149d09 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ Python 3 教程 ============ + +[Python 3 教程](https://www.liaoxuefeng.com/wiki/1016959663602400) From b8a97b6145deabf344e2e0be7a592693913583cd Mon Sep 17 00:00:00 2001 From: Tim Gates Date: Wed, 23 Dec 2020 23:15:00 +1100 Subject: [PATCH 02/15] docs: fix simple typo, verticle -> vertical There is a small typo in samples/micropython/rccar/main.py. Should read `vertical` rather than `verticle`. --- samples/micropython/rccar/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/micropython/rccar/main.py b/samples/micropython/rccar/main.py index 595133d5..cf18c927 100644 --- a/samples/micropython/rccar/main.py +++ b/samples/micropython/rccar/main.py @@ -61,7 +61,7 @@ def joystickLoop(robot, eventFile): return robot.inactive() elif t == 3: if c == 1: - # Left stick & verticle: + # Left stick & vertical: speed = 0 if v < 32768: # up: From 756b1f73a9eade7bc10cfa36b471bf25c0d625b3 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Wed, 26 Apr 2023 09:11:33 +0800 Subject: [PATCH 03/15] refactor --- samples/basic/{ => hello}/hello.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename samples/basic/{ => hello}/hello.py (100%) diff --git a/samples/basic/hello.py b/samples/basic/hello/hello.py similarity index 100% rename from samples/basic/hello.py rename to samples/basic/hello/hello.py From 841c1e74ddedea07cd90ad121c51c95d82ed8ac5 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Wed, 26 Apr 2023 11:30:17 +0800 Subject: [PATCH 04/15] Create CNAME --- docs/CNAME | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/CNAME diff --git a/docs/CNAME b/docs/CNAME new file mode 100644 index 00000000..fac3311c --- /dev/null +++ b/docs/CNAME @@ -0,0 +1 @@ +learn-python3.itranswarp.com \ No newline at end of file From 7c317c39a69921d3ee5e965f3c5dfd512515ebe3 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Wed, 26 Apr 2023 11:32:22 +0800 Subject: [PATCH 05/15] Create pyscript_plugin.js --- docs/pyscript_plugin.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docs/pyscript_plugin.js diff --git a/docs/pyscript_plugin.js b/docs/pyscript_plugin.js new file mode 100644 index 00000000..89e1ad83 --- /dev/null +++ b/docs/pyscript_plugin.js @@ -0,0 +1,6 @@ +export default class LearnPython3Plugin { + afterStartup(runtime) { + console.log('[plugin] pyscript startup.'); + window.__pyscript_ready__ = true; + } +} From f983b17f6b8c6848c76158c892e3b77e47b5e7c8 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Wed, 26 Apr 2023 20:23:20 +0800 Subject: [PATCH 06/15] Update pyscript_plugin.js --- docs/pyscript_plugin.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/pyscript_plugin.js b/docs/pyscript_plugin.js index 89e1ad83..d3d6af84 100644 --- a/docs/pyscript_plugin.js +++ b/docs/pyscript_plugin.js @@ -3,4 +3,12 @@ export default class LearnPython3Plugin { console.log('[plugin] pyscript startup.'); window.__pyscript_ready__ = true; } + + afterPyScriptExec(opt) { + let + tag = opt.pyScriptTag, + outputId = tag.getAttribute('output'), + $btn = $('button[outputId=' + outputId + ']); + $button.removeAttr('disabled'); + } } From 480131640736b93d9ea782af33aeb4d567ae83a8 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Wed, 26 Apr 2023 20:26:26 +0800 Subject: [PATCH 07/15] Update pyscript_plugin.js --- docs/pyscript_plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pyscript_plugin.js b/docs/pyscript_plugin.js index d3d6af84..48b74e6a 100644 --- a/docs/pyscript_plugin.js +++ b/docs/pyscript_plugin.js @@ -8,7 +8,7 @@ export default class LearnPython3Plugin { let tag = opt.pyScriptTag, outputId = tag.getAttribute('output'), - $btn = $('button[outputId=' + outputId + ']); + $btn = $('button[outputId=' + outputId + ']'); $button.removeAttr('disabled'); } } From 5f0f6cb5c18403928403242c9fa7510a3cb8baa5 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Wed, 26 Apr 2023 20:30:29 +0800 Subject: [PATCH 08/15] Update pyscript_plugin.js --- docs/pyscript_plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pyscript_plugin.js b/docs/pyscript_plugin.js index 48b74e6a..bd30a4c2 100644 --- a/docs/pyscript_plugin.js +++ b/docs/pyscript_plugin.js @@ -9,6 +9,6 @@ export default class LearnPython3Plugin { tag = opt.pyScriptTag, outputId = tag.getAttribute('output'), $btn = $('button[outputId=' + outputId + ']'); - $button.removeAttr('disabled'); + $btn.removeAttr('disabled'); } } From 9dfc8a1425c1ce93f9fc7a70ee033f4d95c8dba5 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Wed, 26 Apr 2023 20:32:05 +0800 Subject: [PATCH 09/15] Update pyscript_plugin.js --- docs/pyscript_plugin.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/pyscript_plugin.js b/docs/pyscript_plugin.js index bd30a4c2..1fac7731 100644 --- a/docs/pyscript_plugin.js +++ b/docs/pyscript_plugin.js @@ -8,7 +8,10 @@ export default class LearnPython3Plugin { let tag = opt.pyScriptTag, outputId = tag.getAttribute('output'), - $btn = $('button[outputId=' + outputId + ']'); + $btn = $('button[outputId=' + outputId + ']'), + $i = $btn.find('i'); + $i.removeClass('uk-icon-spinner'); + $i.removeClass('uk-icon-spin'); $btn.removeAttr('disabled'); } } From 147c587f20026bede42224948a1e7d6c28c3bd48 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Wed, 26 Apr 2023 21:16:26 +0800 Subject: [PATCH 10/15] Update pyscript_plugin.js --- docs/pyscript_plugin.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pyscript_plugin.js b/docs/pyscript_plugin.js index 1fac7731..5ed45f9b 100644 --- a/docs/pyscript_plugin.js +++ b/docs/pyscript_plugin.js @@ -5,6 +5,8 @@ export default class LearnPython3Plugin { } afterPyScriptExec(opt) { + console.log('Result >>>'); + console.log(opt.result); let tag = opt.pyScriptTag, outputId = tag.getAttribute('output'), From 5189b15c88c98d32e5dd5822e57a13d602df0866 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Wed, 26 Apr 2023 21:21:09 +0800 Subject: [PATCH 11/15] Update pyscript_plugin.js --- docs/pyscript_plugin.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/pyscript_plugin.js b/docs/pyscript_plugin.js index 5ed45f9b..835b1f64 100644 --- a/docs/pyscript_plugin.js +++ b/docs/pyscript_plugin.js @@ -5,8 +5,7 @@ export default class LearnPython3Plugin { } afterPyScriptExec(opt) { - console.log('Result >>>'); - console.log(opt.result); + console.log(opt); let tag = opt.pyScriptTag, outputId = tag.getAttribute('output'), @@ -16,4 +15,9 @@ export default class LearnPython3Plugin { $i.removeClass('uk-icon-spin'); $btn.removeAttr('disabled'); } + + onUserError(err) { + console.log('Error >>>'); + console.error(err); + } } From 4164c5cd8627b91b33c7a7b4500cb923d5fc56ec Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Wed, 26 Apr 2023 21:54:44 +0800 Subject: [PATCH 12/15] Update pyscript_plugin.js --- docs/pyscript_plugin.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/pyscript_plugin.js b/docs/pyscript_plugin.js index 835b1f64..ef28f964 100644 --- a/docs/pyscript_plugin.js +++ b/docs/pyscript_plugin.js @@ -5,19 +5,31 @@ export default class LearnPython3Plugin { } afterPyScriptExec(opt) { - console.log(opt); let tag = opt.pyScriptTag, outputId = tag.getAttribute('output'), $btn = $('button[outputId=' + outputId + ']'), $i = $btn.find('i'); - $i.removeClass('uk-icon-spinner'); - $i.removeClass('uk-icon-spin'); + $i.removeClass('uk-icon-spinner'); + $i.removeClass('uk-icon-spin'); $btn.removeAttr('disabled'); + let err = $(tag).find('pre.py-error').text(); + if (err) { + let + $out = $('#' + outputId), + s = $out.text(); + if (s) { + s = s + '\n' + err; + } else { + s = err; + } + $out.text(s); + $out.addClass('uk-alert-danger'); + } } onUserError(err) { - console.log('Error >>>'); + console.log('Error >>>'); console.error(err); } } From 90ec8263cf6211470399bf62ac21d8c86a4fa769 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Wed, 26 Apr 2023 21:59:47 +0800 Subject: [PATCH 13/15] Update pyscript_plugin.js --- docs/pyscript_plugin.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/pyscript_plugin.js b/docs/pyscript_plugin.js index ef28f964..2b1cf6fe 100644 --- a/docs/pyscript_plugin.js +++ b/docs/pyscript_plugin.js @@ -13,17 +13,17 @@ export default class LearnPython3Plugin { $i.removeClass('uk-icon-spinner'); $i.removeClass('uk-icon-spin'); $btn.removeAttr('disabled'); - let err = $(tag).find('pre.py-error').text(); + let err = $(tag).find('pre.py-error').html(); if (err) { let $out = $('#' + outputId), - s = $out.text(); + s = $out.html(); if (s) { - s = s + '\n' + err; + s = s + '
' + err; } else { s = err; } - $out.text(s); + $out.html(s); $out.addClass('uk-alert-danger'); } } From b35486349f60ea47edf11fc45da5157767e3cb07 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Wed, 26 Apr 2023 22:14:33 +0800 Subject: [PATCH 14/15] Update pyscript_plugin.js --- docs/pyscript_plugin.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/pyscript_plugin.js b/docs/pyscript_plugin.js index 2b1cf6fe..39e7bae7 100644 --- a/docs/pyscript_plugin.js +++ b/docs/pyscript_plugin.js @@ -18,11 +18,7 @@ export default class LearnPython3Plugin { let $out = $('#' + outputId), s = $out.html(); - if (s) { - s = s + '
' + err; - } else { - s = err; - } + s = s + err.replaceAll(' ', ' '); $out.html(s); $out.addClass('uk-alert-danger'); } From 27f49401960be8233d2c52b9e214ac9da7be22d3 Mon Sep 17 00:00:00 2001 From: Michael Liao Date: Tue, 3 Oct 2023 13:05:24 +0800 Subject: [PATCH 15/15] Create do_match.py --- samples/basic/do_match.py | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 samples/basic/do_match.py diff --git a/samples/basic/do_match.py b/samples/basic/do_match.py new file mode 100644 index 00000000..b14fe51f --- /dev/null +++ b/samples/basic/do_match.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# 简单匹配: +print('-- simple match --') + +score = 'A' + +match score: + case 'A': + print('score is A.') + case 'B': + print('score is B.') + case 'C': + print('score is C.') + case _: + print('score is ???.') + +# 复杂匹配: +print('-- complex match --') + +age = 15 + +match age: + case x if x < 10: + print('< 10 years old.') + case 10: + print('10 years old.') + case 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18: + print('11~18 years old.') + case 19: + print('19 years old.') + case _: + print('not sure.') + +# 列表匹配: +print('-- match list --') + +args = ['gcc', 'hello.c', 'world.c'] +# args = ['clean'] +# args = ['gcc'] + +match args: + # 如果仅出现gcc,报错: + case ['gcc']: + print('gcc: missing source file(s).') + # 出现gcc,且至少指定了一个文件: + case ['gcc', file1, *files]: + print('gcc compile: ' + file1 + ', ' + ', '.join(files)) + # 仅出现clean: + case ['clean']: + print('clean') + case _: + print('invalid command.')