Is it possible to convert a Unicode string to a regular string? If it's just an alphabet, I'll do something about it, but in addition to the alphabet, it also contains special characters such as , and $
type-conversion string python unicode
Must be applied in order
import unicodedata
title = u"hello $#@ i'm Demi"
print(unicodedata.normalize('NFKD', title))
print(unicodedata.normalize('NFKD', title).encode('ascii','ignore'))
title = u"Klüft skräms inför på fédéral électoral große"
print(unicodedata.normalize('NFKD', title))
print(unicodedata.normalize('NFKD', title).encode('ascii','ignore'))
Output:
hello $#@ i'm Demi
b"hello $#@ i'm Demi"
Klüft skräms inför på fédéral électoral große
b'Kluft skrams infor pa federal electoral groe'
© 2024 OneMinuteCode. All rights reserved.