[Tutor] Why begin a function name with an underscore
Hugo Arts
hugo.yoshi at gmail.com
Tue Aug 28 11:43:12 CEST 2012
On Tue, Aug 28, 2012 at 11:13 AM, Richard D. Moores <rdmoores at gmail.com>wrote:
> On Tue, Aug 28, 2012 at 1:21 AM, Timo <timomlists at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120828/c9142678/attachment.html>
More information about the Tutor
mailing list