how to decode an ascii string with backslash x \\x codes
I am trying to decode from a Brazilian Portogese text: 'Demais Subfun\xc3\xa7\xc3\xb5es 12' It should be 'Demais Subfunções 12' >> a.decode('unicode_escape') >> a.encode('unicode_escape') >> a.decode('ascii') >> a.encode('ascii') all give: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 13: ordinal not in range(128) on the other hand this gives: >> print a.encode('utf-8') Demais Subfun├â┬º├â┬Áes 12 >> print a Demais Subfunções 12 Martijn Pieters You have binary data that is not ASCII encoded. The \xhh codepoints indicate your data is encoded with a different codec, and