On 8/25/2015 10:32 AM, random832 at fastmail.us wrote:
On Mon, Aug 24, 2015, at 22:12, Andrew Wang wrote:
[question snipped]

And, now, your moment of zen:

Huh?? I fail to see the point of this buggy code.

def isa(ob, cl):
raise ob
except cl:
return 1
else: return 0

The extra marginal '>' quote makes it look like this buggy code was
posted by Andrew, but it comes from random832. In 3.x, both ob and cl
must be exceptions and isa(1, int) cannot work. In 2.7, ob must be an
exception or old-style class (not documented that I see).

raise 1

Traceback (most recent call last):
    File "<pyshell#32>", line 1, in <module>
      raise 1
TypeError: exceptions must be old-style classes or derived from
BaseException, not int

Hence, isa(1, int) raises TypeError instead of returning 1. If 'else' is
changed to 'except', it returns 0 instead of 1.

Terry Jan Reedy

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 4 | next ›
Discussion Overview
grouppython-list @
postedAug 25, '15 at 2:12a
activeAug 25, '15 at 5:42p



site design / logo © 2018 Grokbase