newbie question about unicode

Genie T nguyenhuuthanh at gmail.com
Sat Jun 23 03:06:52 EDT 2007


On Jun 23, 1:06 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Sat, 23 Jun 2007 01:10:19 -0300, Genie T <nguyenhuuth... at gmail.com>
> escribió:
>
> > can anybody tell me whether these two expressions have the same
> > meanings?
>
> > s = u'<unicode string here>'
> > s1 = s.encode('utf-8')
>
> > AND
>
> > s1 = unicode(s,'utf-8')
>
> No - but consider this (assuming your terminal uses utf-8):
>
> py> u1 = u'<some text here>'
> py> s1 = u1.encode('utf-8')
> py>
> py> s2 = '<some text here>'
> py> u2 = s2.decode('utf-8')
> py>
> py> type(u1), type(u2)
> (<type 'unicode'>, <type 'unicode'>)
> py> u1==u2
> True
> py> type(s1), type(s2)
> (<type 'str'>, <type 'str'>)
> py> s1==s2
> True
>
> --
> Gabriel Genellina

Thanks, i'm clear now




More information about the Python-list mailing list