Skip to content

Instantly share code, notes, and snippets.

@fcamel
Created July 20, 2009 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcamel/150365 to your computer and use it in GitHub Desktop.
Save fcamel/150365 to your computer and use it in GitHub Desktop.
#!/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