[Tutor] unicode nightmare

danielle davout danielle.davout at gmail.com
Wed Nov 10 20:01:20 CET 2010


Hi,
I really badly need any start of explanation ..
Please help me !
I have got  a list  of 64 generators from which I generate files.
58 give what I expected
1 is getting me mad, not the first, not the last the fifth...
I simplify it to
v = u'\u0eb4'
X = (1,)
gen = ((v ,v) for x in X for y in X)

What can be so wrong in this line, around it to give the 1lined file
ໄ:ໄ
where ໄ "is" not u'\u0eb4' but  u'\u0ec4' though a direct printing looks OK
To write the file corresponding to my nth generator of my list h I use
    def ecrire(n):
        f= codecs.open("G"+str(n),"w","utf8")
        for x, tx in h[n]:
            f.write((x + U":"+ tx))
            f.write('\n')
        f.close()
But In its non simplified form
    h.append( (x + v + y ,tr[x]+ tr[v]+ tr[y]) for x in CC for y in OFC) )
 before I  have a chance to write anything in the file G5
I have got the KeyError: u'\u0ec4'
yes tr is a dictionary that doesn't have u'\u0ec4' as a key
but tr[v] is well definied ...

(# /usr/lib/python2.5/encodings/utf_8.pyc matches
/usr/lib/python2.5/encodings/utf_8.py
import encodings.utf_8 # precompiled from /usr/lib/python2.5/encodings/utf_8.pyc
Python 2.5.2 (r252:60911, Jan 24 2010, 14:53:14)
[GCC 4.3.2] on linux2)


More information about the Tutor mailing list