Ò
Ò»Ê×Ê«
#------------------------------------------------
class MyError(Exception):
def __init__(self):
self.message = u'Some Chinese:$BCfJ8(B'
def __str__(self):
return self.message.encode('utf8')
#------------------------------------------------
This is an exception that I defined. I have to pass it to third
party libraries.
As many libraries simply use str(e) to log, if I don't encode it in
__str___, they will fail.
But I am not quite certain if it's the right thing to do. Shouldn't
every library expect to use unicode everywhere?
Shouldn't they use something like :
log(unicode(e))
class MyError(Exception):
def __init__(self):
self.message = u'Some Chinese:$BCfJ8(B'
def __str__(self):
return self.message.encode('utf8')
#------------------------------------------------
This is an exception that I defined. I have to pass it to third
party libraries.
As many libraries simply use str(e) to log, if I don't encode it in
__str___, they will fail.
But I am not quite certain if it's the right thing to do. Shouldn't
every library expect to use unicode everywhere?
Shouldn't they use something like :
log(unicode(e))