problems with  character

deelan ggg at zzz.it
Tue Mar 22 15:30:34 EST 2005


jdonnell wrote:
> I have a mysql database with characters like      » in it. I'm
> trying to write a python script to remove these, but I'm having a
> really hard time.

use the "hammer" recipe. i'm using it to create URL-friendly
fragment from latin-1 album titles:

<http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/251871>
(check the last comment, "a cleaner solution"
for a better implementation).

it basically hammers down accented chars like à and Â
to the most near ASCII representation.

since you receive string data as str from mysql
object first convert them as unicode with:

u = unicode('Â', 'latin-1')

then feed u to the hammer function (the fix_unicode at the
end).

HTH,
deelan

-- 
"Però è bello sapere che, di questi tempi spietati, almeno
un mistero sopravvive: l'età di Afef Jnifen." -- dagospia.com



More information about the Python-list mailing list