Unicode strings as arguments to exceptions

Terry Reedy tjreedy at udel.edu
Thu Jan 16 18:09:20 EST 2014


On 1/16/2014 7:34 AM, Ernest Adrogué wrote:
> 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.

Fixed at some point in 3.x. In 3.4b2:
 >>> ValueError(b'a')
ValueError(b'a',)
 >>> ValueError('a')
ValueError('a',)



-- 
Terry Jan Reedy





More information about the Python-list mailing list