On Tue, Feb 5, 2013 at 10:16 AM, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > from numbers import Number > if isinstance(x, Number): > ... > else: > raise TypeError > > > or Ask Forgiveness: > > x + 0 > ... > > > where in both cases the ellipsis ... is the code I actually care about.
Caveat to my previous post: I would NOT indent the function body for the sake of this check. I'd negate it: if not isinstance(x, Number): raise TypeError (hopefully with further information in the TypeError). I don't like the code style that puts conditions, then more code, then error handling - I prefer to fail-and-bail. ChrisA -- http://mail.python.org/mailman/listinfo/python-list