newbie question about unicode

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Jun 23 02:06:06 EDT 2007


En Sat, 23 Jun 2007 01:10:19 -0300, Genie T <nguyenhuuthanh 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




More information about the Python-list mailing list