From 6f233c47e4ca3e0622357f2b1e927813d0e49588 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Sun, 29 Sep 2013 21:23:53 +0200 Subject: [PATCH] useful python trick --- remplace_accents.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 remplace_accents.py diff --git a/remplace_accents.py b/remplace_accents.py new file mode 100644 index 0000000..687b750 --- /dev/null +++ b/remplace_accents.py @@ -0,0 +1,27 @@ +#!/usr/bin/python +# -*- coding:utf8 -*- + +""" Tout petit script à importé partout où on en a besoin + pour enlever les accents/œ/æ/trémas d'une chaîne unicode +""" + +def remplace_accents(chaine): + remplacements = { + u"’":u"'", + u"á":u"a", u"à":u"a", u"â":u"a", u"ä":u"a", + u"Á":u"A", u"À":u"A", u"Â":u"A", u"Ä":u"A", + u"é":u"e", u"è":u"e", u"ê":u"e", u"ë":u"e", + u"É":u"E", u"È":u"E", u"Ê":u"E", u"Ë":u"E", + u"í":u"i", u"ì":u"i", u"î":u"i", u"ï":u"i", + u"Í":u"I", u"Ì":u"I", u"Î":u"I", u"Ï":u"I", + u"ó":u"o", u"ò":u"o", u"ô":u"o", u"ö":u"o", + u"Ó":u"O", u"Ò":u"O", u"Ô":u"O", u"Ö":u"O", + u"ú":u"u", u"ù":u"u", u"û":u"u", u"ü":u"u", + u"Ú":u"U", u"Ù":u"U", u"Û":u"U", u"Ü":u"U", + u"ý":u"y", u"ỳ":u"y", u"ŷ":u"y", u"ÿ":u"y", + u"Ý":u"Y", u"Ỳ":u"Y", u"Ŷ":u"Y", u"Ÿ":u"Y", + u"œ":u"oe", u"æ":u"ae", + u"Œ":u"OE", u"Æ":u"AE"} + for avant,apres in remplacements.items(): + chaine=chaine.replace(avant,apres) + return chaine -- 2.39.2