What does unicodedata.normalize do in python?

前端 未结 2 456
长发绾君心
长发绾君心 2021-01-01 00:31

I have the following code:

import unicodedata
my_var = \"this is a string\"
my_var2 = \" Esta es una oración que está en español \"
my_var3 = unicodedata.nor         


        
2条回答
  •  没有蜡笔的小新
    2021-01-01 01:07

    You need to specify the encoding type.

    Then you need to use unicode instead of string as arguments of normalize()

    # -*- coding: utf-8 -*-
    
    import unicodedata
    my_var = u"this is a string"
    my_var2 = u" Esta es una oración que está en español "
    my_var3 = unicodedata.normalize(u'NFKD', my_var2).encode('ascii', 'ignore').decode('utf8')
    output = my_var + my_var3
    print(output)
    

提交回复
热议问题