How to replace unicode characters by ascii characters in Python (perl script given)?

前端 未结 5 648
日久生厌
日久生厌 2020-12-05 01:15

I am trying to learn python and couldn\'t figure out how to translate the following perl script to python:

#!/usr/bin/perl -w                     

use open          


        
5条回答
  •  孤城傲影
    2020-12-05 01:39

    For converting to ASCII you might want to try ASCII, Dammit or this recipe, which boils down to:

    >>> title = u"Klüft skräms inför på fédéral électoral große"
    >>> import unicodedata
    >>> unicodedata.normalize('NFKD', title).encode('ascii','ignore')
    'Kluft skrams infor pa federal electoral groe'
    

提交回复
热议问题