0
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)
1
  • 1
    Try b''.join(packet) or b''.join(packet).decode('cp1252'). (Note that cp1252 is merely a guess.) Commented Jun 10, 2021 at 18:47

1 Answer 1

1

A list of byte strings must use a byte string with the join. e.g. 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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.