[Chicago] understanding unicode problems
Carl Karsten
carl at personnelware.com
Fri Nov 16 00:04:53 CET 2007
Kumar McMillan wrote:
> On Nov 15, 2007 4:13 PM, Carl Karsten <carl at personnelware.com> wrote:
>> of course now a unicode problem just hit me.
>>
>> i use the django admin to enter Ivan Krstic'
>> and reportlab spits out: http://dev.personnelware.com/carl/a/IvanK1.pdf
>>
>> so pretty much 100% python.
>>
>> I am told:
>>
>> > Make sure that you are using utf-8 and not some other encoding, such as
>> > latin-1.
>>
>> But I really don't know what that means, nor do I even know how to debug this.
>
> I wrote up a little something about it when it finally clicked for me:
> http://farmdev.com/thoughts/23/what-i-thought-i-knew-about-unicode-in-python-amounted-to-nothing/
> (I was in the same spot, I knew I *should* use UTF-8 but wasn't sure
> how or why or what that even implied)
Tagged.
>
> In my email reader the name shows up as Ivan Krstic' (with a single
> quote at the end) so I'm not sure what character is really at the end
> of his name but .... if Django is dealing with unicode now (which
> Feihong says it is) then you probably just need to encode it into a
> UTF-8 bytestream before you write to the PDF file. I.E. pdf.write("%s
> %s" % (first_name.encode('utf-8'), last_name.encode('utf-8')).
'ascii' codec can't decode byte 0xc4 in position 10: ordinal not in range(128)
981. # draw the string using the function that matches the alignment:
982. s = obj.getProp("expr", returnException=True)
983.
984. if isinstance(s, basestring):
985. s = s.encode(self.Encoding) ...
986. else:
987. s = unicode(s)
988. func(posx, 0, s)
Will that ever hit the else case?
Carl K
More information about the Chicago
mailing list