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 diff --git a/docs/pyscript_plugin.js b/docs/pyscript_plugin.js new file mode 100644 index 00000000..39e7bae7 --- /dev/null +++ b/docs/pyscript_plugin.js @@ -0,0 +1,31 @@ +export default class LearnPython3Plugin { + afterStartup(runtime) { + console.log('[plugin] pyscript startup.'); + window.__pyscript_ready__ = true; + } + + afterPyScriptExec(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'); + $btn.removeAttr('disabled'); + let err = $(tag).find('pre.py-error').html(); + if (err) { + let + $out = $('#' + outputId), + s = $out.html(); + s = s + err.replaceAll(' ', ' '); + $out.html(s); + $out.addClass('uk-alert-danger'); + } + } + + onUserError(err) { + console.log('Error >>>'); + console.error(err); + } +} 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.') 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 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: