You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: bytes() constructor only supports encoding arguments 'utf8', 'utf-8' and 'ascii'. Other encodings like 'latin-1' are not supported. Other string forms such as 'UTF8' are not supported.
cause: MicroPython is optimised for embedded systems and has limited codec support to save code size. `A similar restriction applies to str.encode() <cpydiff_types_str_encode_encoding>`. See also `unicode_support`.
workaround: Implement other encoding conversions manually by parsing the result of str.encode() or bytes() constructor.
"""
# Both CPython and MicroPython can encode this emoji as UTF-8 bytes
print(bytes("😀", "utf8"))
# Both CPython and MicroPython will fail to encode this emoji as ASCII bytes
try:
print(bytes("😀", "ascii"))
exceptUnicodeError:
print("UnicodeError")
# Other encodings or string formats aren't accepted by MicroPython