Builtin functions and exceptions

All builtin functions and exceptions are described here. They are also available via builtins module.

Functions and types

abs()
all()
any()
bin()
class bool
class bytearray

Difference for RI5

As with the array class, in RI5 this has methods append(), extend() and decode() that isn’t in standard Micropython.

class bytes

See CPython documentation: bytes.

It’s missing a lot of the more complicated or specialized functions of that class though.

callable()
chr()
classmethod()
compile()
class complex
delattr(obj, name)

The argument name should be a string, and this function deletes the named attribute from the object given by obj.

class dict
dir()
divmod()
enumerate()
eval()
exec()
execfile()

Not in Python 3, but it does show up in Micropython.

filter()
class float

In MicroPython, this class doesn’t have any methods.

class frozenset
getattr()
globals()
hasattr()
hash()
help()
hex()
id()

Difference for RI5

The input() function has been removed in RI5 - not unreasonably!

class int
classmethod from_bytes(bytes, byteorder)

In MicroPython, byteorder parameter must be positional (this is compatible with CPython).

to_bytes(size, byteorder)

In MicroPython, byteorder parameter must be positional (this is compatible with CPython).

isinstance()
issubclass()
iter()
len()
class list
locals()
map()
max()
class memoryview

In MicroPython, this doesn’t have any methods and can only be used with indices and slicing.

min()
next()
class object
oct()
open(file, mode='r', buffering=- 1, encoding=None)

On RI5, this allows one to four arguments, so not as many as the corresponding CPython function.

ord()
pow()
print()

Difference for RI5

On the RI5, this function has been overwritten by an alias to a new builtin spikeprint()

class property
range()
repr()
reversed()
round()
class set
setattr()
class slice

The slice builtin is the type that slice objects have.

sorted()
spikeprint()

Difference for RI5

A new function that overwrites print(), presumably so that print responses can be successfully sent back over the link to the controlling app.

staticmethod()
class str

See CPython documentation: str.

It’s missing a lot of the more complicated or specialized functions of that class though.

sum()
super()
class tuple
class type
zip()

Exceptions

exception BaseException
exception ArithmeticError
exception AssertionError
exception AttributeError
exception EOFError
exception Exception
exception GeneratorExit
exception ImportError
exception IndentationError
exception IndexError
exception KeyboardInterrupt
exception KeyError
exception LookupError
exception MemoryError
exception NameError
exception NotImplementedError
exception OSError

See CPython documentation: OSError. MicroPython doesn’t implement errno attribute, instead use the standard way to access exception arguments: exc.args[0].

exception OverflowError
exception RuntimeError
exception StopAsyncIteration
exception StopIteration
exception SyntaxError
exception SystemExit

See CPython documentation: SystemExit.

exception TypeError

See CPython documentation: TypeError.

exception UnicodeError
exception ValueError
exception ZeroDivisionError

Constants

Ellipsis

The same as the ellipsis literal “…”. Special value used mostly in conjunction with extended slicing syntax for user-defined container data types.

NotImplemented

Special value which should be returned by the binary special methods (e.g. __eq__(), __lt__(), __add__(), __rsub__(), etc.) to indicate that the operation is not implemented with respect to the other type; may be returned by the in-place binary special methods (e.g. __imul__(), __iand__(), etc.) for the same purpose. It should not be evaluated in a boolean context.

Note: When a binary (or in-place) method returns NotImplemented the interpreter will try the reflected operation on the other type (or some other fallback, depending on the operator). If all attempts return NotImplemented, the interpreter will raise an appropriate exception. Incorrectly returning NotImplemented will result in a misleading error message or the NotImplemented value being returned to Python code.

See Implementing the arithmetic operations for examples.

Note: NotImplementedError and NotImplemented are not interchangeable, even though they have similar names and purposes. See NotImplementedError for details on when to use it.