According to this test:
ENCODING = 'utf-8'
test_cases = [
'aaaaa',
'ááááá',
'ℕℤℚℝℂ',
]
FORMAT = '%-10s %5d %-10s %-10s %5d %-10s %10s'
for text in test_cases :
decoded = text.decode(ENCODING)
unicoded = unicode(text, ENCODING)
equal = decoded == unicoded
print FORMAT % (decoded, len(decoded), type(decoded), unicoded, len(unicoded), type(unicoded), equal)
There is no difference between .decode()and unicode():
aaaaa 5 <type 'unicode'> aaaaa 5 <type 'unicode'> True
ááááá 5 <type 'unicode'> ááááá 5 <type 'unicode'> True
ℕℤℚℝℂ 5 <type 'unicode'> ℕℤℚℝℂ 5 <type 'unicode'> True
I'm right? If so, why do we have two different ways to solve the same thing? Which one should I use? Is there any subtle difference?
source
share