[Zope-dev] BUG: ValueError while changing height of the template edit window
Guido van Rossum
guido@python.org
Wed, 11 Dec 2002 12:01:49 -0500
> > Can you provide an example of raising a unicode error like this:
> >
> > u = makeUnicodeString() # your choice of function
> > int(u)
>
> In Python 2.3, I get this:
>
> >>> int(u"\u1234")
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> UnicodeEncodeError: 'decimal' codec can't encode character '\u1234' in position 0: invalid decimal Unicode string
> >>>
>
> In Python 2.2, this raises ValueError.
I spoke too soon. UnicodeEncodeError is a subclass of ValueError. So
catching ValueError from int(str_or_unicode) is the way to go. Who's
writing that Zope 3 style guide again?
--Guido van Rossum (home page: http://www.python.org/~guido/)