G
G
gd1xza2020-12-31 13:31:01
Python
gd1xza, 2020-12-31 13:31:01

How to turn bytes into python string?

There are bytes:

ebytes = b"\x08\x00\x00\x00\x00\x01\x00\x24\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x61\x62\x63\x64\x65\x66\x67\x68\x69"

There is a required result:
sbytes = "08 00 00 00 00 01 00 24 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 61 62 63 64 65 66 67 68 69"


it's all written by hand. how to make string from bytes? such

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Yakushenko, 2020-12-31
@gd1xza

repr(ebytes)[2:-1].replace('\\x', ' ').strip()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question