Simple ascii url encoding with python

后端 未结 6 1272
不思量自难忘°
不思量自难忘° 2021-01-16 12:23

look at that:

import urllib
print urllib.urlencode(dict(bla=\'Ã\'))

the output is

bla=%C3%BC

what I want

6条回答
  •  借酒劲吻你
    2021-01-16 13:00

    Have a look at unicode transliteration in python:

    from unidecode import unidecode
    print unidecode(u"\u5317\u4EB0")
    
    # That prints: Bei Jing
    

    In your case:

    bla='Ã'
    print unidecode(bla)
    'A'
    

    This is a third party library, which can be easily installed via:

    $ git clone http://code.zemanta.com/tsolc/git/unidecode
    $ cd unidecode
    $ python setup.py install
    

提交回复
热议问题