On Tue, Aug 28, 2012 at 6:00 AM, Peter Otten <__pete...@web.de> wrote: > > Anyway here's an alternative implementation: > >>>> def vi(x): > ... if not isinstance(x, numbers.Number): > ... raise TypeError > ... if not int(x) == x: > ... raise ValueError
You could test against numbers.Integral. But it's not fool-proof. Someone can register an incompatible class with the abstract base class (ABC). >>> import numbers >>> isinstance("42", numbers.Integral) False >>> numbers.Integral.register(str) >>> isinstance("42", numbers.Integral) True http://docs.python.org/library/abc _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor