For example, a is a bytes composed of 8 bytes
a=b'/x00/x01/x02/x03/x04/x05/x06/x07'
How do I extract the first four bytes of a=to form a new bytes
I tried the following method
for i in range(0,4):
c[i]=a[i]
But the result c is a list not bytes
But it doesn’t work a[i] is of type int
How to make c equal to the first 4 bytes of extracted a
That is, the result is c=b'/x00/x01/x02/x03'
高洛峰2017-05-18 10:49:58
,不是
/
>>> a=b'\x00\x01\x02\x03\x04\x05\x06\x07'
>>> len(a)
8
>>> a[:4]
b'\x00\x01\x02\x03'