unicode bit me

anuraguniyal at yahoo.com anuraguniyal at yahoo.com
Fri May 8 16:53:44 CEST 2009


#how can I print a list of object which may return unicode
representation?
# -*- coding: utf-8 -*-

class A(object):

    def __unicode__(self):
        return u"©au"

    __str__ = __repr__ = __unicode__

a = A()

try:
    print a # doesn't work?
except UnicodeEncodeError,e:
    print e
try:
    print unicode(a) # works, ok fine, great
except UnicodeEncodeError,e:
    print e
try:
    print unicode([a]) # what!!!! doesn't work?
except UnicodeEncodeError,e:
    print e
"""
Now how can I print a list of object which may return unicode
representation?
loop/map is not an option as it goes much deepr in my real code
any can anyoen explain what is happening here under the hood?
"""



More information about the Python-list mailing list