======python 2.6 ======
import sys

print sys.getdefaultencoding()

s = u"\u20ac"
print s.encode("utf-8")


$ python2.6 1test.py
ascii
€


=====python 3.1 =======
import sys

print(sys.getdefaultencoding())

s = "€"
print(s.encode("utf-8"))
print(s)


$ python3.1 1test.py
utf-8
b'\xe2\x82\xac'

Traceback (most recent call last):
File "1test.py", line 7, in <module>
print(s)
UnicodeEncodeError: 'ascii' codec can't encode character '\u20ac' in
position 0: ordinal not in range(12


I don't understand why I'm getting an encode error in python 3.1.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to