Modules

Generated Thu 16 May 2019 04:48:09 UTC

array

Looking for integer not implemented

Sample code:

import array
print(1 in array.array('B', b'12'))
CPy output: uPy output:
False
/bin/sh: 1: ../unix/micropython: not found

Array deletion not implemented

Sample code:

import array
a = array.array('b', (1, 2, 3))
del a[1]
print(a)
CPy output: uPy output:
array('b', [1, 3])
/bin/sh: 1: ../unix/micropython: not found

Subscript with step != 1 is not yet implemented

Sample code:

import array
a = array.array('b', (1, 2, 3))
print(a[3:2:2])
CPy output: uPy output:
array('b')
/bin/sh: 1: ../unix/micropython: not found

deque

Deque not implemented

Workaround: Use regular lists. micropython-lib has implementation of collections.deque.

Sample code:

import collections
D = collections.deque()
print(D)
CPy output: uPy output:
deque([])
/bin/sh: 1: ../unix/micropython: not found

json

JSON module does not throw exception when object is not serialisable

Sample code:

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 output: uPy output:
TypeError
/bin/sh: 1: ../unix/micropython: not found

struct

Struct pack with too few args, not checked by uPy

Sample code:

import struct
try:
    print(struct.pack('bb', 1))
    print('Should not get here')
except:
    print('struct.error')
CPy output: uPy output:
struct.error
/bin/sh: 1: ../unix/micropython: not found

Struct pack with too many args, not checked by uPy

Sample code:

import struct
try:
    print(struct.pack('bb', 1, 2, 3))
    print('Should not get here')
except:
    print('struct.error')
CPy output: uPy output:
struct.error
/bin/sh: 1: ../unix/micropython: not found

sys

Overriding sys.stdin, sys.stdout and sys.stderr not possible

Cause: They are stored in read-only memory.

Sample code:

import sys
sys.stdin = None
print(sys.stdin)
CPy output: uPy output:
None
/bin/sh: 1: ../unix/micropython: not found