__unicode__ method for exception object

Manlio Perillo manlio_perilloNO at SPAMlibero.it
Sat Jul 7 14:26:15 EDT 2007


Hi all.

I have just noticed that exception objects does not handle well Unicode 
arguments.

>>> e = RuntimeError(u'àèìòù')
>>> str(e)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode characters in position 
0-4: ordinal not in range(128)
>>> unicode(e)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode characters in position 
0-4: ordinal not in range(128)


C object struct does not have a tp_unicode slot (maybe it will be added 
in Python 3000?), however I think that the Base Exception class should 
implement the __unicode__ method.

Any problems in doing so?
I have not yet required this feature in the Python tracker.


Thanks  Manlio Perillo



More information about the Python-list mailing list