Unicode strings as arguments to exceptions

Ernest Adrogué nfdisco at gmail.com
Thu Jan 16 07:34:08 EST 2014


Hi,

There seems to be some inconsistency in the way exceptions handle Unicode
strings.  For instance, KeyError seems to not have a problem with them

>>> raise KeyError('a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'a'
>>> raise KeyError(u'ä')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: u'\xe4'

On the other hand ValueError doesn't print anything.

>>> raise ValueError('a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: a
>>> raise ValueError(u'ä')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError

I'm using Python 2.7.6 on a Unix machine.



More information about the Python-list mailing list