``Type-checking'' with dir()
Alex Martelli
aleaxit at yahoo.com
Sun Aug 17 09:15:11 EDT 2003
Raymond Hettinger wrote:
...
> The code becomes especially clean if you use the sets module:
>
> if not Set(["__getslice__", "__len__"]) < Set(dir(a)):
> raise InterfaceError(a)
I think you want a <= here -- otherwise, an InterfaceError would
be raised in the (unlikely, sure;-) case in which dir(a) has
ONLY the __len__ and __getslice__ entries.
(BTW, of course: __getslice__ is obsolete, and properly substituted
by __getitem__ taking a slice object as an 'index' in today's
well-implemented sequences -- so, this is not a good example
[not Raymond's fault, of course, as it was what the OP used]).
Alex
More information about the Python-list
mailing list