On 3 March 2010 20:44, Giorgio <[email protected]> wrote:
>>>> s = "ciao è ciao"
>>>> print s
> ciao è ciao
>>>> s.encode('utf-8')
> Traceback (most recent call last):
> File "<pyshell#2>", line 1, in <module>
> s.encode('utf-8')
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 5:
> ordinal not in range(128)
It is confusing but once understand how it works it makes sense.
You start with a 8bit string so you will want to *decode* it to unicode string.
>>> s = "ciao è ciao"
>>> us = s.decode('latin-1')
>>> us
u'ciao \xe8 ciao'
>>> us2 = s.decode('iso-8859-1')
>>> us2
u'ciao \xe8 ciao'
Greets
Sander
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor