decoding bytearray without Unicode errors #14244
Answered
by
peterhinch
Rumidom
asked this question in
Using MicroPython
-
hi, how can i decode a bytearray with bytes that cant be translated, and replace those with unknown? on python print(b'\xff\xff\xff\xff'.decode('utf8','replace')) outputs: '����' but on Micropython I still get a UnicodeError >>> print(b'\xff\xff\xff\xff'.decode('utf8','replace'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeError: |
Beta Was this translation helpful? Give feedback.
Answered by
peterhinch
Apr 4, 2024
Replies: 2 comments 3 replies
-
I think the code is here - if so, the feature has not yet been implemented, |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Rumidom
-
Or try: byte_array = b'rats\xff foo'
bytearray([x if x <= 127 else ord('?') for x in byte_array]) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the code is here - if so, the feature has not yet been implemented,