Ascii characters
Fredrik Lundh
fredrik at pythonware.com
Tue Jun 26 10:13:23 EDT 2001
Johan Daine wrote:
> I am using using swish++ with Zope in a french context.
> In orger to filter the user requests, I need to filter accented
> characters to the unaccented char.
assuming you have 2.0 or later, something like this
should work:
import unicodedata, string
def maketable():
# build iso-latin-1 to "undotted" ascii translation table
table = range(256)
for i in table:
x = unicodedata.decomposition(unichr(i))
if x and x[0] == "0":
table[i] = int(x.split()[0], 16)
return string.join(map(chr, table), "")
text = "...some accented iso-latin-1 text..."
noaccents = maketable()
undotted_text = string.translate(text, noaccents)
hope this helps!
</F>
<!-- (the eff-bot guide to) the python standard library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list