モジュール¶
Generated Sat 22 Dec 2018 08:00:49 UTC
array¶
整数の探索は未実装¶
サンプルコード:
import array
print(1 in array.array('B', b'12'))
| CPy 出力: | uPy 出力: |
False
|
/bin/sh: ../ports/unix/micropython: No such file or directory
|
配列要素の削除は未実装¶
サンプルコード:
import array
a = array.array('b', (1, 2, 3))
del a[1]
print(a)
| CPy 出力: | uPy 出力: |
array('b', [1, 3])
|
/bin/sh: ../ports/unix/micropython: No such file or directory
|
ステップが 1 でないスライスは未実装¶
サンプルコード:
import array
a = array.array('b', (1, 2, 3))
print(a[3:2:2])
| CPy 出力: | uPy 出力: |
array('b')
|
/bin/sh: ../ports/unix/micropython: No such file or directory
|
builtins¶
next() の第2引数は未実装¶
Cause: MicroPython is optimised for code space.
回避策: val = next(it, deflt) とする代わりに、次のようにする:
try:
val = next(it)
except StopIteration:
val = deflt
サンプルコード:
print(next(iter(range(0)), 42))
| CPy 出力: | uPy 出力: |
42
|
/bin/sh: ../ports/unix/micropython: No such file or directory
|
deque¶
deque は未実装¶
回避策: 通常のリストを使用してください。micropython-lib には collections.deque の実装があります。
サンプルコード:
import collections
D = collections.deque()
print(D)
| CPy 出力: | uPy 出力: |
deque([])
|
/bin/sh: ../ports/unix/micropython: No such file or directory
|
json¶
json モジュールは、オブジェクトが直列化可能でなくとも例外を発生しない¶
サンプルコード:
import json
a = bytes(x for x in range(256))
try:
z = json.dumps(a)
x = json.loads(z)
print('Should not get here')
except TypeError:
print('TypeError')
| CPy 出力: | uPy 出力: |
TypeError
|
/bin/sh: ../ports/unix/micropython: No such file or directory
|
struct¶
struct の pack で引数が少なすぎても uPy はチェックしない¶
サンプルコード:
import struct
try:
print(struct.pack('bb', 1))
print('Should not get here')
except:
print('struct.error')
| CPy 出力: | uPy 出力: |
struct.error
|
/bin/sh: ../ports/unix/micropython: No such file or directory
|
struct の pack で引数が多すぎても uPy はチェックしない¶
サンプルコード:
import struct
try:
print(struct.pack('bb', 1, 2, 3))
print('Should not get here')
except:
print('struct.error')
| CPy 出力: | uPy 出力: |
struct.error
|
/bin/sh: ../ports/unix/micropython: No such file or directory
|