File: class/Workbook/Examples/Lecture8/classexc2.py

>>> class B: pass
...
>>> class C(B): pass              # C isa B
...
>>> class D(C): pass              # D isa C
...
>>> for klass in (B, C, D):
...     try:
...         instance = klass()
...         raise instance
...     except D:                 # order matters:
...         print 'D'             # most specific first,
...     except C:                 # else prints B, B, B
...         print 'C'
...     except B:
...         print 'B'



[Home page] Books Code Blog Python Author Train Find ©M.Lutz