Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64114

Re: Unicode strings as arguments to exceptions

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Unicode strings as arguments to exceptions
Date 2014-01-16 18:09 -0500
References <20140116123408.GA5524@doriath.local>
Newsgroups comp.lang.python
Message-ID <mailman.5610.1389913787.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Unicode strings as arguments to exceptions Terry Reedy <tjreedy@udel.edu> - 2014-01-16 18:09 -0500

csiph-web