mysterious unicode

jim-on-linux inq1ltd at verizon.net
Wed Mar 21 01:26:33 CET 2007


On Tuesday 20 March 2007 18:35, Gerry wrote:
> I'm using pyExcelerator and xlrd to read and
> write data from and to two spreadsheets.
>
> I created the "read" spreadsheet by importing a
> text file - and I had no unicode aspirations.
>
> When I read a cell, it appears to be unicode
> u'Q1", say.
>
> I can try cleaning it, like this:
>
>
>     try:
>         s.encode("ascii", "replace")
>     except AttributeError:
>         pass
>
>
> which seems to work.  Here's the mysterious
> part (aside from why anything was unicode in
> the first place):
>
>                 print >> debug, "c=", col,
> "r=", row, "v=", value, "qno=", qno
>                 tuple = (qno, family)
>                 try:
>                     data[tuple].append(value)
>                 except:
>                     data[tuple] = [value]
>                 print >> debug, "!!!", col,
> row, qno, family, tuple, value, data[tuple]
>
> which produces:
>
> c= 1 r= 3 v= 4 qno= Q1
> !!! 1 3 Q1 O (u'Q1', 'O') 4 [1, u' ', 4]
>
> where qno seems to be a vanilla Q1, but a tuple
> using qno is (u'Q1', ...).
>
> Can somebody help me out?


I have been getting the same thing using SQLite3 
when extracting data fron an SQLite3 database.  I 
take the database info which is in a list and do

name = str.record[0]
rather than 
name = record[0]

So far, I havn't had any problems.
For some reason the unicode u is removed.
I havn't wanted to spend the time to figure out 
why.

jim-on-linux
http://www.inqvista.com























More information about the Python-list mailing list