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

Peng Yu pengyu.ut at gmail.com
Sat Sep 17 23:30:56 EDT 2016


On Sat, Sep 17, 2016 at 3:20 PM, Martin Schöön <martin.schoon at gmail.com> wrote:
> Den 2016-09-17 skrev Kouli <dev at kou.li>:
>> Hello, try the Unidecode module - https://pypi.python.org/pypi/Unidecode.

I don't find a way to make it print oe for ö. Could anybody please
advise what is the correct way to do it?

==> main.py <==
#!/usr/bin/env python
# vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8:

import sys
from unidecode import unidecode
print unidecode(sys.argv[1].decode('utf-8'))


==> main.sh <==
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

./main.py Schöön

$ ./main.sh
Schoon

>> 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.
>
> Side note from Sweden. Å, ä and ö are not accented characters in our
> language. They are characters of their own. If you want to look up
> someone called Öhman in the phone directory you go to the Ö section
> not the O section.
>
> Related anecdote from Phoenix AZ. By now you have noticed my family
> name: Schöön. On airline tickets and boarding passes in the U.S. it
> gets spelled Schoeoen. This landed me in a special security check
> once. After a while the youngish lady performing the search started
> to look like 1+1 did not sum up to 2. She looked at my passport
> and boarding pass again and asked why I was there with her. I pointed
> at another young lady, the one that 'scrutinized' passports and
> boarding passes while chatting with a friend and said "She told me
> to go over here." "Wait here, I have to talk to my supervisor."
>
> A few minutes passed (I was alone in the enhances security check
> throughout...) and then "I am sorry but you should not have had
> to go through here. There was a mistake."
>
> So there you are: If you are a middle aged, caucasian guy with
> a passport from northern Europe and no 'funny' letters in your name
> your are not a threat in the eyes of TSA in Arizona.
>
> Sorry for wasting the bandwidth.
>
> /Martin
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Regards,
Peng



More information about the Python-list mailing list