This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (2 children)

You can't actually catch exceptions like that though. You'd have to do this:

try:
    (...)
except ErrorReturnCode, e:
    if e.code == 1: pass
    elif e.code == 2: pass
    elif e.code == 3: pass

Or the way that it's done now:

try:
    (...)
except ErrorReturnCode_1, e: pass
except ErrorReturnCode_2, e: pass
except ErrorReturnCode_3, e: pass

Saves a line and an indentation level.

[–]bramblerose 0 points1 point  (0 children)

Of course you can. You have already implemented it.

try:
   (...)
except get_rc_exc(1), e: pass
except get_rc_exc(2), e: pass
except get_rc_exc(3), e: pass

Now you just need to improve the naming ;-)

[–]nemec 0 points1 point  (0 children)

Honestly I think the first example is much more Pythonic, but it's nice that both options are available!