unicode() vs. s.decode()

Thorsten Kampe thorsten at thorstenkampe.de
Thu Aug 6 10:32:34 EDT 2009


* Michael Ströder (Wed, 05 Aug 2009 16:43:09 +0200)
> These both expressions are equivalent but which is faster or should be
> used for any reason?
> 
> u = unicode(s,'utf-8')
> 
> u = s.decode('utf-8') # looks nicer

"decode" was added in Python 2.2 for the sake of symmetry to encode(). 
It's essentially the same as unicode() and I wouldn't be surprised if it 
is exactly the same. I don't think any measurable speed increase will be 
noticeable between those two.

Thorsten



More information about the Python-list mailing list