简体   繁体   中英

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

How to converts an abnormal character into a normal character (eg, an unicode character), In other words, decoding an abnormal characters/string like 'â€Â' to reveal its contents?

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

Output:

 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'

I would like to print the string without these characters (â€Â)

Yes, You can try this..You can use encode to ASCII if you don't need to translate the non-ASCII characters:

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

#output

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM