简体   繁体   中英

Joining specific bytes data in python3.6

a = 192
b = 168

packet = []
packet.append(bytes([a]))
packet.append(bytes([b]))

#Since the packet has only bytes data for numeral range 0-255 how can I convert it to str so that I can perform join

packet = ''.join(packet)

A list of byte strings must use a byte string with the join. eg b''.join(packet) . But considering that bytes() can be constructed from a list of byte-ranged integers, just convert later:

>>> packet=[]
>>> packet.append(192)
>>> packet.append(168)
>>> bytes(packet)
b'\xc0\xa8'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM