1

I need help on converting accented character to unicode. Is there any function or module to do it ? I would like a function which does something like that:

def char_to_unicode(text)
    text.replace("à", \u00e0)
    text.replace("â", \u00e2)
    # and this for all accented characters...
    return text
Xentiie
  • 31
  • 4

1 Answers1

1

Isn't optimized but it's all I can get:

def char_to_unicode(text):
    text.replace("à", "\u00e0")
    text.replace("ä", "\u00e4")
    text.replace("â", "\u00e2")
    text.replace("ç", "\u00e7")
    text.replace("è", "\u00e8")
    text.replace("é", "\u00e9")
    text.replace("ê", "\u00ea")
    text.replace("ë", "\u00eb")
    text.replace("î", "\u00ee")
    text.replace("ï", "\u00ef")
    text.replace("ô", "\u00f4")
    text.replace("ö", "\u00f6")
    text.replace("ù", "\u00f9")
    text.replace("û", "\u00fb")
    text.replace("ü", "\u00fc")
    return text

def unicode_to_char(text):
    text.replace("\u00e0", "à")
    text.replace("\u00e4", "ä")
    text.replace("\u00e2", "â")
    text.replace("\u00e7", "ç")
    text.replace("\u00e8", "è")
    text.replace("\u00e9", "é")
    text.replace("\u00ea", "ê")
    text.replace("\u00eb", "ë")
    text.replace("\u00ee", "î")
    text.replace("\u00ef", "ï")
    text.replace("\u00f4", "ô")
    text.replace("\u00f6", "ö")
    text.replace("\u00f9", "ù")
    text.replace("\u00fb", "û")
    text.replace("\u00fc", "ü")
    return text
Xentiie
  • 31
  • 4