2017-12-24から1日間の記事一覧

MicroPython メモ 14 / クラスとインスタンスと

参考: Programming the BBC Micro:bit: Getting Started With MicroPython, pp.75-76 これまでに出てきた button_a や display は何らかのクラスのインスタンスである。どのクラスのインスタンスであるかは type() で確認できる。 ひとつのクラスは属性とメ…

MicroPython メモ 13 / モジュールのインポート

参考: Programming the BBC micro:bit: Getting Started with MicroPython, p73-75 モジュールの中身を確認する。 from モジュール名 import * という構文でモジュールの中身を全部インポートする。 下のようにしてもモジュールの中身全部がインポートされる…

MicroPython メモ 12 / 例外処理

参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.68-69 これだとインデックスが 5 を超えたところでエラーが出てプログラムが停止してしまう (Lua だと、存在しない要素を参照したときは nil が返ってくる)。 list = [0, 1, 2, 3…

MicroPython メモ 11 / micro:bit の内部ストレージにデータを書き込む、内部ストレージからデータを読み取る

参考: Programming the BBC micro:bit: Getting Started with MicroPython, p.69-71 from microbit import * with open("test.txt", "w") as sute: sute.write("ABC") with open("test.txt") as sute: message = sute.read() while True: display.scroll(mes…