将 python 中的异常字符转换为正常字符(例如,unicode 字符)

converts an abnormal character into a normal character (e.g., an unicode character) in python

如何将异常字符转换为正常字符(例如unicode字符),换句话说,解码异常characters/string如'â€Â'以显示其内容?

context='This Service does not use these “cookies†explicitly. However, the app may'
context1= context.encode('utf8') # encode('ascii')
print(context1)

输出:

 b'This Service does not use these \xc3\x83\xc2\xa2\xc3\x82\xc2\x80\xc3\x82\xc2\x9ccookies\xc3\x83\xc2\xa2\xc3\x82\xc2\x80\xc3\x82\xc2\x9d explicitly. However, the app may'

我想打印没有这些字符的字符串 (

是的,你可以试试这个..如果你不需要翻译非 ASCII 字符,你可以使用编码为 ASCII:

content.encode('ascii','ignore')

#output

This Service does not use these cookies explicitly. However, the app may'