What encoding does u'...' syntax use?

Ron Garret rNOSPAMon at flownet.com
Fri Feb 20 14:48:45 EST 2009


I would have thought that the answer would be: the default encoding 
(duh!)  But empirically this appears not to be the case:

>>> unicode('\xb5')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb5 in position 0: 
ordinal not in range(128)
>>> u'\xb5'
u'\xb5'
>>> print u'\xb5'
µ

(That last character shows up as a micron sign despite the fact that my 
default encoding is ascii, so it seems to me that that unicode string 
must somehow have picked up a latin-1 encoding.)

rg



More information about the Python-list mailing list