A Unicode problem -HELP

"Martin v. Löwis" martin at v.loewis.de
Fri May 12 01:22:54 EDT 2006


manstey wrote:
> 1. I have # -*- coding: UTF-8 -*- as my first line.
> 2. In Wing IDE I have set Default Encoding to UTF-8
> 3. I have imported codecs and opened and written my file, which doesn't
> have a BOM, as encoding=UTF-8
> 4. I have written a dictionary for translation, with entries such as
> {'F':u'\u0254'} and a function to do the translation
> 
> Everything works fine, except that my output file, when loaded in
> unicode aware emeditor has
> (u'F', u'\u0254')

I couldn't quite follow this description: what is "your output file"
(in what step is it created?), and how does

(u'F', u'\u0254')

get into this file? What is the precise Python statement that
produces that line of output?

> So my questions are:
> 1. How do I do this?

Most likely, you use (directly or indirectly) the repr() function
to convert a  tuple into that string. You shouldn't do that;
instead, you should format the elements of the tuple yourself, e.g.
through

print >>f, u"('%s', '%s')" % value

Regards,
Martin



More information about the Python-list mailing list