exception handing

Rhymes rhymes at myself.com
Sat Jun 29 11:41:52 EDT 2002


I'm reading "Learning Python" and in the section "gotchas"
of the exception handling chapter the book itself states
that the exception matching is made by identity not equality.
It also write an example such as this:

>>> ex1 = "spam"
>>> ex2 = "spam"
>>>
>>> ex1 == ex2, ex1 is ex2
(1, 0)

<--- here i get (1, 1) ---->

>>> try:
...    raise ex1
... except ex1:
...    print 'got it'
...
got it
>>> try:
...    raise ex1
... except ex2:
...    print 'Got it'
...
Traceback (innermost last):
  File "<stdin>", line 2, in ?
spam

but in my Python 2.2 i don't get back any error from the interpreter
about the second example... why? What has changed (since 1.5 release)
about objects identity?

--
Rhymes
rhymes at myself.com
" ride or die "



More information about the Python-list mailing list