mysterious unicode

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Mar 20 19:29:35 EDT 2007


En Tue, 20 Mar 2007 19:35:00 -0300, Gerry <gerard.blais at gmail.com>  
escribió:

> 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', ...).

I bet qno was unicode from start. When you print an unicode object, you  
get the "unadorned" contents. When you print a tuple, it uses repr() on  
each item.

py> qno = u"Q1"
py> qno
u'Q1'
py> print qno
Q1
py> print (qno,2)
(u'Q1', 2)

-- 
Gabriel Genellina




More information about the Python-list mailing list