![]() |
|
|
|||||||
![]() |
Python - Is this the right way to use unicode in a user defined Exception? |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
#------------------------------------------------
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)) Ò»Ê×Ê« |
|
|
|
|
#2 |
|
Posts: n/a
|
一首诗 wrote:
> #------------------------------------------------ > class MyError(Exception): > def __init__(self): > self.message = u'Some Chinese:ä¸*æ–‡' > > 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)) In 3.0, text is unicode. So libraries will mostly expect it. Terry Reedy |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| creating user defined service in windows | suresh_rtp | Software | 0 | 05-05-2009 08:34 AM |
| java.net.SocketException: Broken pipe exception at HttpServletRequest | sadasivar | Software | 0 | 03-11-2008 04:40 AM |
| exception unknown software exception error - Excel.exe | mfinamore | Software | 0 | 11-15-2007 04:54 PM |
| Exception in thread "main" java.lang.NoClassDefFoundError: | prakash.nmsp@gmail.com | Software | 0 | 06-29-2007 10:03 AM |
| how to overcome the nullpointer exception | arputharaj | Software | 0 | 11-11-2006 07:05 AM |