モジュール¶
Generated Wed 06 Mar 2019 15:05:45 UTC
array¶
整数の探索は未実装¶
サンプルコード:
import array
print(1 in array.array('B', b'12'))
CPy 出力: | uPy 出力: |
False
|
Traceback (most recent call last):
File "<stdin>", line 8, in <module>
NotImplementedError:
|
配列要素の削除は未実装¶
サンプルコード:
import array
a = array.array('b', (1, 2, 3))
del a[1]
print(a)
CPy 出力: | uPy 出力: |
array('b', [1, 3])
|
Traceback (most recent call last):
File "<stdin>", line 9, in <module>
TypeError: 'array' object doesn't support item deletion
|
ステップが 1 でないスライスは未実装¶
サンプルコード:
import array
a = array.array('b', (1, 2, 3))
print(a[3:2:2])
CPy 出力: | uPy 出力: |
array('b')
|
Traceback (most recent call last):
File "<stdin>", line 9, in <module>
NotImplementedError: only slices with step=1 (aka None) are supported
|
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
|
Traceback (most recent call last):
File "<stdin>", line 12, in <module>
TypeError: function takes 1 positional arguments but 2 were given
|
deque¶
deque は未実装¶
回避策: 通常のリストを使用してください。micropython-lib には collections.deque の実装があります。
サンプルコード:
import collections
D = collections.deque()
print(D)
CPy 出力: | uPy 出力: |
deque([])
|
Traceback (most recent call last):
File "<stdin>", line 8, in <module>
TypeError: function missing 2 required positional arguments
|
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
|
Should not get here
|
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
|
b'\x01\x00'
Should not get here
|
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
|
b'\x01\x02'
Should not get here
|