On Tue, Aug 28, 2012 at 11:13 AM, Richard D. Moores <rdmoo...@gmail.com>wrote:

> On Tue, Aug 28, 2012 at 1:21 AM, Timo <timomli...@gmail.com> wrote:
> > Op 28-08-12 10:06, Richard D. Moores schreef:
>
> >> What if I wanted 3., 1234., etc. to be considered ints, as they are by
> >> _validate_int()  ?
> >
> >
> >>>> isinstance(3., (int, float))
> > True
> >
> > Because 3. is a float, not int.
>
> And
> >>> isinstance(3.7, (int, float))
> True
>
> No, I'm asking for something equivalent to _validate_int().
>
> Dick
>
>
kind of a hack, but how about:

def validate_int(x):
    return  int(x) == x

>>> validate_int(3.4)
False
>>> validate_int(3.)
True

I know enough about floating point numbers to not trust this in obscure
corner cases, but it might suffice for you.

HTH,
Hugo
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to