1

I want to decode a string, which is already encoded in UTF-8

"\x6d\xc3\xbc\x6c\x6c\x65\x72\x20\x69\x73\x74\x20\x63\x6f\x6f\x6c\x21"

I cannot find a way to decode a string without getting such a error message text_utf8 = text_utf8.decode("utf-8") AttributeError: 'str' object has no attribute 'decode'

Is there a way to force a string to decode?

EDIT: I can´t use a Bytestring because my program imports a string out of a text file

1 Answers1

0

You can use bytes function

byte_string = bytes(text_utf8, "utf-8")
decoded_string = byte_string.decode("utf-8")
tomerar
  • 805
  • 5
  • 10
  • This is just roundtripping without change. You'll get `text_utf8 == decoded_string` for any input. – lenz Jan 07 '23 at 22:47