check if object is number

Steven Bethard steven.bethard at gmail.com
Tue Feb 15 11:21:22 EST 2005


Antoon Pardon wrote:
> Op 2005-02-11, Steven Bethard schreef <steven.bethard at gmail.com>:
> 
>>George Sakkis wrote:
>>
>>>"Steven Bethard" <steven.bethard at gmail.com> wrote in message
>>>news:gcidnb9g_ojxnpDfRVn-tA at comcast.com...
>>>
>>>
>>>>Is there a good way to determine if an object is a numeric type?
>>>
>>>In your example, what does your application consider to be numeric?
>>
>>Well, here's the basic code:
>>
>>def f(max=None):
>>     ...
>>     while max is None or n <= max:
>>         ...
>>         # complicated incrementing of n
>>
>>So for 'max', technically all I need is <= support.  However, the code 
>>also depends on the fact that after incrementing 'n' enough, it will 
>>eventually exceed 'max'.  Currently, ints, longs, floats, and Decimals 
>>will all meet this behavior.
> 
> Actually no, floats don't meet this behaviour or more specifically
> floats don't guarantee this behaviour. It depends of course on
> your implementation of f, but it is possible with floats to keep
> incrementing and never reach a maximum.

My code won't hit this corner case.  I'm incrementing with integers.

Steve



More information about the Python-list mailing list