[Tutor] Unicode problems
Ed Singleton
singletoned at gmail.com
Tue Aug 29 22:39:49 CEST 2006
I've been having unicode problems in python on Mac OS 10.4.
I googled for it and found a good page in Dive Into Python that I
thought might help
(http://www.diveintopython.org/xml_processing/unicode.html).
I tried following the instructions and set my default encoding using a
sitecustomize.py, but got the following:
>>> import sys
>>> sys.getdefaultencoding()
'utf-8'
>>> s = u'La Pe\xf1a'
>>> print s
Traceback (most recent call last):
File "<stdin>", line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in
position 5: ordinal not in range(128)
>>>
As I understand it, that should work. I tried using different
character sets (like latin-1, etc), but none of them work.
The main problem I am having is in getting python not to give an
error when it encounters a sterling currency sign (£, pound sign here
in UK), which I suspect might be some wider problem on the mac as when
I type that character in the terminal it shows a # (but in Python it
shows a £).
Any help, or hints greatly appreciated.
Thanks
Ed
More information about the Tutor
mailing list