This snipped thorws an error, I couldn't find a solution so far.
from array import array
arr = array('B',[8, 3, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 2])
ab = arr.tobytes()
array.frombytes(ab)
TypeError Traceback (most recent call last)
Cell In[117], line 4
2 arr = array('B',[8, 3, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 2])
3 ab = arr.tobytes()
----> 4 array.frombytes(ab)
TypeError: descriptor 'frombytes' for 'array.array' objects doesn't apply to a 'bytes' object
I treid this in Python 3.10.8 and a fresh 3.11.0 environment. No luck with neither
frombytesmethod defined in thearrayclass is an ordinary instance method, not aclassmethodorstaticmethod. It needs to be called on an instance of the class. Calling it from the class itself like this means thatabwill be used asself, which doesn't work. The linked duplicate is the most popular I could find on this theme; I will keep looking for a more general canonical.frombytes (b'')doesn't apply to a bytes object, which is the whole point of frombytes.fromwhatevermethods are supposed to be classmethods, since conventionally the purpose is to create an instance. See for exampleint.from_bytes.