How to convert unicode characters to ASCII string in Python

3 Answers

0 votes
import unicodedata

us = u'har, Har, hár, Hár, hār, hår, hær, Mobiltillbehör, klä'

s = unicodedata.normalize('NFKD', us).encode('ascii', 'ignore')

print(s)



  
  
'''
run:
  
b'har, Har, har, Har, har, har, hr, Mobiltillbehor, kla'

'''

 



answered Apr 24, 2021 by avibootz
0 votes
import unicodedata

us = u'har, Har, hár, Hár, hār, hår, hær, Mobiltillbehör, klä'

s = unicodedata.normalize('NFKD', us).encode('ascii', 'ignore').decode()

print(s)



  
  
'''
run:
  
har, Har, har, Har, har, har, hr, Mobiltillbehor, kla

'''

 



answered Apr 24, 2021 by avibootz
0 votes
import unicodedata

us = u'æãåā@àáâäEzh5ëal.JÀs5ÛÒŹZ!j>jöłÒę'

s = unicodedata.normalize('NFKD', us).encode('ascii', 'ignore').decode()

print(s)



  
  
'''
run:
  
aaa@aaaaEzh5eal.JAs5UOZZ!j>joOe

'''

 



answered Apr 24, 2021 by avibootz
...