[Tutor] Why begin a function name with an underscore
Mark Lawrence
breamoreboy at yahoo.co.uk
Tue Aug 28 11:13:27 CEST 2012
On 28/08/2012 05:13, Richard D. Moores wrote:
> 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?
>
> Dick Moores
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
I rarely if ever test for any object type. I certainly wouldn't bother
with the function above, I'd just like the program bomb and fix the
fault at source. YMMV.
--
Cheers.
Mark Lawrence.
More information about the Tutor
mailing list