Page 1 of 1
NotImplementedError. Loop for bytearray.
Posted: Sat Jul 18, 2020 11:39 am
by prem111
Code: Select all
def escape(msg):
escaped = bytearray()
reserved = bytearray(b"\x7E\x7D\x11\x13")
escaped.append(msg[0])
for m in msg[1:]:
if m in reserved:
escaped.append(0x7D)
escaped.append(m ^ 0x20)
else:
escaped.append(m)
return escaped
File "<stdin>", line 8, in escape
NotImplementedError:
How can you do?
Thanks for help!
Re: NotImplementedError. Loop for bytearray.
Posted: Sat Jul 18, 2020 10:24 pm
by dhylands
It looks like using 'in' with a bytearray isn't supported.
If you replace it with:
then it seems to work properly.
Re: NotImplementedError. Loop for bytearray.
Posted: Sun Jul 19, 2020 5:32 am
by prem111
Thanks for help.
Re: NotImplementedError. Loop for bytearray.
Posted: Mon Jul 20, 2020 4:22 am
by jimmo
prem111 wrote: ↑Sun Jul 19, 2020 5:32 am
Thanks for help.
One extra point on this -- although it would have been nice if what you wanted was implemented, it's actually a lot more efficient to use dhylands' suggestion instead, as it does not involve allocating or copying a bytearray every time this function is called.