Re: [Python-ideas] syntax to continue into the next subsequent except block

Sept. 20, 2012
10:22 a.m.
I would like to share that the original suggestion inspired me on the following (mis-)adventure. Cheers, V James Powell switch = lambda val: type('', (BaseException,), {'val': val})() case = lambda pred: type('', (type,), {'__subclasscheck__': staticmethod(lambda x: pred(x.val))})('',(BaseException,),{}) default = BaseException #x = '%s' x = 12 try:raise switch(x) except case( lambda x: x % 2 == 0 ): print "It's even!" except case( lambda x: x % 2 == 1 ): print "It's odd!" except default: print "It's a joke!"
4563
Age (days ago)
4563
Last active (days ago)
0 comments
1 participants
participants (1)
-
V James Powell