Short confusing example with unicode, print, and __str__

G

Gerard Brunick

I really don't understand the following behavior:
.... def __init__(self, s): self.s = s
.... def __str__(self): return self.s
....Print using just c: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
position 3: ordinal not in range(128)Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
position 3: ordinal not in range(128)

Why would "print c.s" work but the other two cases throw an exception?
Any help understanding this would be greatly appreciated.

Thanks in advance,
Gerard
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top