Created
July 20, 2009 14:36
-
-
Save fcamel/150365 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- encoding: utf8 -*- | |
class A(object): | |
def __init__(self, s): | |
self.s = s | |
def __str__(self): | |
return self.s | |
a = A(u'中文') | |
print a.__str__().encode('utf8') | |
print str(a).encode('utf8') | |
##### Here is the output ##### | |
# | |
# 中文 | |
# Traceback (most recent call last): | |
# File "<stdin>", line 14, in <module> | |
# UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) | |
# | |
# shell returned 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment