Skip to content Skip to sidebar Skip to footer

Read Hex Characters And Convert Them To Utf-8 Using Python 3

I have a file data.txt containing this string: M\xc3\xbchle\x0astra\xc3\x9fe Now the file needs to be read and the hex code interpreted as utf-8. So far this is my try: #!/usr/bin

Solution 1:

Try

line = line.decode('unicode_escape').encode('latin-1').decode('utf8')

Post a Comment for "Read Hex Characters And Convert Them To Utf-8 Using Python 3"