如何在字符串中解码ASCII字符

时间:2019-12-13 15:10:52

标签: python-3.x ascii decode

我在包含非ASCII字符的字符串中包含ASCII字符。当我尝试对其进行解码时,我得到一个奇怪的框字符。如何正确解码这些字符?

string = 'So you\u0019ve got an elevator pitch(/nivi/2009/04/how-to-write-an-elevator-pitch.html) \u0014 a short, pithy description of why your business is special, exciting, and unique.'.encode()
print(string)
decode = string.decode('unicode_escape')
print("Decoded: ", decode)

输出:

b'So you\x19ve got an elevator pitch(/nivi/2009/04/how-to-write-an-elevator-pitch.html) \x14 a short, pithy description of why your business is special, exciting, and unique.'
Decoded:  So youve got an elevator pitch(/nivi/2009/04/how-to-write-an-elevator-pitch.html)  a short, pithy description of why your business is special, exciting, and unique.

0 个答案:

没有答案