How to convert 'ö' to 'oe' or 'o' (or other similar things) in a string?
Peng Yu
pengyu.ut at gmail.com
Sat Sep 17 12:12:21 EDT 2016
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
More information about the Python-list
mailing list