How to remove accent in Python 3.5 and get a string with unicodedata or other solutions?

前端 未结 4 1951
清酒与你
清酒与你 2021-01-11 16:36

I am trying to get a string to use in google geocoding api.I ve checked a lot of threads but I am still facing problem and I don\'t understand how to solve it.

I nee

4条回答
  •  不要未来只要你来
    2021-01-11 16:48

    You can use the translate() method from python. Here's an example copied from tutorialspoint.com:

    #!/usr/bin/python
    
    from string import maketrans   # Required to call maketrans function.
    
    intab = "aeiou"
    outtab = "12345"
    trantab = maketrans(intab, outtab)
    
    str = "this is string example....wow!!!";
    print str.translate(trantab)
    

    This outputs:

    th3s 3s str3ng 2x1mpl2....w4w!!!

    So you can define what characters you wish to replace more easily than with replace()

提交回复
热议问题