Re: How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?

Kouli dev at kou.li
Sat Sep 17 12:38:50 EDT 2016


Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode.

Kouli

On Sat, Sep 17, 2016 at 6:12 PM, Peng Yu <pengyu.ut at gmail.com> wrote:
> Hi, I want to convert strings in which the characters with accents
> should be converted to the ones without accents. Here is my current
> code.
>
> ========================
>
> $ cat main.sh
> #!/usr/bin/env bash
> # vim: set noexpandtab tabstop=2:
>
> set -v
> ./main.py Förstemann
> ./main.py Frédér8ic@
>
> $ cat main.py
> #!/usr/bin/env python
> # vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8:
>
> import sys
> import unicodedata
> print unicodedata.normalize('NFKD',
> sys.argv[1].decode('utf-8')).encode('ascii', 'ignore')
>
> ========================
>
> The complication is that some characters have more than one way of
> conversions. E.g., 'ö' can be converted to either 'oe' or 'o'. I want
> to get all the possible conversions of a string. Does anybody know a
> good way to do so? Thanks.
>
> --
> Regards,
> Peng
> --
> https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list