On Mon, Jul 14, 2008 at 12:40 PM, Tim Cook <timothywayne.c ook@gmail.comwr ote:
Part of it depends on where you're getting them from. If they are in
your source code, just define them like this:
°
u'\xb0'
If they're coming from an external source, you have to know the
encoding they're being sent in. Then you can decode them into
unicode, like this:
u'\xb0'
°
--
Jerry
if I say units=unicode(" °"). I get
UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xc2 in position 0:
ordinal not in range(128)
>
If I try x=unicode.decod e(x,'utf-8'). I get
TypeError: descriptor 'decode' requires a 'unicode' object but received
a 'str'
>
What is the correct way to interpret these symbols that come to me as a
string?
UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xc2 in position 0:
ordinal not in range(128)
>
If I try x=unicode.decod e(x,'utf-8'). I get
TypeError: descriptor 'decode' requires a 'unicode' object but received
a 'str'
>
What is the correct way to interpret these symbols that come to me as a
string?
your source code, just define them like this:
>>units = u"°"
>>print units
>>print units
>>print repr(units)
If they're coming from an external source, you have to know the
encoding they're being sent in. Then you can decode them into
unicode, like this:
>>units = "°"
>>unicode_uni ts = units.decode('L atin-1')
>>print repr(unicode_un its)
>>unicode_uni ts = units.decode('L atin-1')
>>print repr(unicode_un its)
>>print unicode_units
--
Jerry
Comment