Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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)
b''.join(packet)
b''.join(packet).decode('cp1252')
cp1252
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:
bytes()
>>> packet=[] >>> packet.append(192) >>> packet.append(168) >>> bytes(packet) b'\xc0\xa8'
Add a comment
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
b''.join(packet)orb''.join(packet).decode('cp1252'). (Note thatcp1252is merely a guess.)