strings in python 3.x

Joined
Aug 24, 2009
Messages
1
Reaction score
0
==============
import sys

print sys.getdefaultencoding()

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

$ python2.6 1test.py
ascii



================
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(128)


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top