[Tutor] Why begin a function name with an underscore
Jerry Zhang
jerry.scofield at gmail.com
Tue Aug 28 09:13:02 CEST 2012
2012/8/28 Richard D. Moores <rdmoores at gmail.com>
> On Mon, Aug 27, 2012 at 6:33 PM, Japhy Bartlett <japhy at pearachute.com>
> wrote:
>
> > something like:
> >
> > def _validate_int(obj):
> > """Raise an exception if obj is not an integer."""
> > m = int(obj + 0) # May raise TypeError.
> > if obj != m:
> > raise ValueError('expected an integer but got %r' % obj)
> >
> >
> > is a really awkward way to test if something's an integer, and checking
> > types in general is usually a sign of larger flaws in laying out useful
> > code.
>
> What the best way to test if something's an integer?
>
>>>a = 4
>>>isinstance(a, int)
True
>
> Dick Moores
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120828/dda949d1/attachment.html>
More information about the Tutor
mailing list