は動作します:`struct.unpack_from`は` bytearray`では動作しませんか?文字列から開梱
>>> import struct
>>> struct.unpack('>h', 'ab')
(24930,)
>>> struct.unpack_from('>h', 'zabx', 1)
(24930,)
が、そのbytearray
場合:
>>> struct.unpack_from('>h', bytearray('zabx'), 1)
Traceback (most recent call last):
File "<ipython-input-4-d58338aafb82>", line 1, in <module>
struct.unpack_from('>h', bytearray('zabx'), 1)
TypeError: unpack_from() argument 1 must be string or read-only buffer, not bytearray
少し奇妙に思われます。私は実際にそれについて何をすべきですか?明らかに私は可能性:
>>> struct.unpack_from('>h', str(bytearray('zabx')), 1)
(24930,)
しかし、私は明示的に周りのメモリの可能性を大量にコピーする回避にしようとしています。
バッファタイプを使用すると、より多くのメモリを占有することなく文字列を参照し、それを引数として渡すことができます。 –