0

I have the following byte array :

b'\x80UTI\xfc\x7f\x00\x00'

I want to convert it to :

'\x80UTI\xfc\x7f\x00\x00'

How can i do that in python ?

Garde Des Ombres
  • 173
  • 1
  • 3
  • 12
  • 3
    Does this answer your question? [Convert bytes to a string](https://stackoverflow.com/questions/606191/convert-bytes-to-a-string) – costaparas Jan 30 '21 at 01:45

1 Answers1

0

Convert it to string with str() and then some string manipulation

>>> x = b'\x80UTI\xfc\x7f\x00\x00'
>>> y = str(x)[1:].strip("'")
>>> print(y)
x80UTI\xfc\x7f\x00\x00
Frank Fourlas
  • 131
  • 1
  • 14
  • Don't parse the structure. There are [better methods](https://stackoverflow.com/questions/606191/convert-bytes-to-a-string) -- also, flag as a duplicate next time. – costaparas Jan 30 '21 at 01:43
  • @Frank This is not the correct way to converting a byte to string. Use decode instead. See https://stackoverflow.com/questions/606191/convert-bytes-to-a-string – Thaer A Jan 30 '21 at 02:55