How to divide python bytes into several bytes
黄舟
黄舟 2017-05-18 10:47:58
0
3
884

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'

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(3)
小葫芦

,不是 /

>>> a=b'\x00\x01\x02\x03\x04\x05\x06\x07'
>>> len(a)
8
>>> a[:4]
b'\x00\x01\x02\x03'
世界只因有你

Thank you I am a beginner haha

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template