On Sat, 12 Feb 2005 16:01:26 -0800, rumours say that Michael Spencer
[EMAIL PROTECTED] might have written:
Yup, that's basically what I'm doing right now. The question was really
how to define that adapter function. =)
Steve
OK - then my entry is:
assert obj+1 = 1
:-)
So -1 is not
Christos TZOTZIOY Georgiou wrote:
On Sat, 12 Feb 2005 16:01:26 -0800, rumours say that Michael Spencer
[EMAIL PROTECTED] might have written:
Yup, that's basically what I'm doing right now. The question was really
how to define that adapter function. =)
Steve
OK - then my entry is:
Steven Bethard wrote:
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
Fredrik Lundh wrote:
Steven Bethard wrote:
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
Op 2005-02-11, Steven Bethard schreef [EMAIL PROTECTED]:
George Sakkis wrote:
Steven Bethard [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
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?
Antoon Pardon wrote:
Op 2005-02-11, Steven Bethard schreef [EMAIL PROTECTED]:
George Sakkis wrote:
Steven Bethard [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Is there a good way to determine if an object is a numeric type?
In your example, what does your application consider to be
Not sure if anyone's mentioned this yet, but just in case they haven't:
Start bit o' Python
import operator
operator.isNumberType(1)
True
operator.isNumberType(1.01)
True
operator.isNumberType('a')
False
operator.isNumberType('1')
False
End bit o' Python
Haven't looked at
Le vendredi 11 Février 2005 20:11, Steven Bethard a écrit :
Is there a good way to determine if an object is a numeric type?
Generally, I avoid type-checks in favor of try/except blocks, but I'm
not sure what to do in this case:
def f(i):
...
if x i:
As I mention below, I mistook the function from my utilities file for a
Python built-in; here's the implementation:
#def isnumber(x):
#Is x a number? We say it is if it has an __int__ method.
#return hasattr(x, '__int__')
--
http://mail.python.org/mailman/listinfo/python-list
Steven Bethard wrote:
Is there a good way to determine if an object is a numeric type?
.
.
.
Ideas?
Maybe this can help?
def isnumber(x):
try:
return(x == x-0)
except:
return False
print '1:\t', isnumber(1)
print '1.25:\t', isnumber(1.25)
print '1.0 / 7:\t', isnumber(1.0 /
marco wrote:
Steven Bethard wrote:
Is there a good way to determine if an object is a numeric type?
Maybe this can help?
def isnumber(x):
try:
return(x == x-0)
except:
return False
Not exactly foolproof:
def isnumber(x):
... try: return (x == x-0)
... except: return
Fredrik Lundh wrote:
Steven Bethard wrote:
Is there a good way to determine if an object is a numeric type?
assert operator.isNumberType(i)
Interesting, thanks! If I read the source right, PyNumber_Check (which
operator.isNumberType is an alias for) basically just returns True if
the object's
John Lenton wrote:
On Fri, Feb 11, 2005 at 01:17:55PM -0700, Steven Bethard wrote:
George Sakkis wrote:
Steven Bethard [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Is there a good way to determine if an object is a numeric type?
In your example, what does your application consider to
George Sakkis wrote:
George Sakkis wrote:
Steven Bethard [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
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):
Oops, my bad. The utilities file I use gets loaded automatically when
I start my interpreter, so I mistook isnumber for a built-in function.
A battle-tested isnumber function is defined in Peter Norvig's utils.py
(http://aima.cs.berkeley.edu/python/utils.py):
#def isnumber(x):
#Is x a
So what you're saying is that 3 = 3.0 should not be allowed, but
3 = SomeUserDefinedNumericClass(3) is ok, although your program knows
nothing a priori about SomeUserDefinedNumericClass. The idea suggested
before, try if x+1 fails or not does not get you far; any class that
overrides
Peter Hansen wrote:
Of course, most of the other definitions of is a number that
have been posted may likewise fail (defined as not doing what the
OP would have wanted, in this case) with a numarray arange.
Or maybe not. (Pretty much all of them will call an arange a
number... would the OP's
Steven Bethard wrote:
Peter Hansen wrote:
Of course, most of the other definitions of is a number that
have been posted may likewise fail (defined as not doing what the
OP would have wanted, in this case) with a numarray arange.
Or maybe not. (Pretty much all of them will call an arange a
Michael Spencer wrote:
Steven Bethard wrote:
Peter Hansen wrote:
Of course, most of the other definitions of is a number that
have been posted may likewise fail (defined as not doing what the
OP would have wanted, in this case) with a numarray arange.
How about explicitly calling an adapter in
Steven Bethard wrote:
Michael Spencer wrote:
Steven Bethard wrote:
Peter Hansen wrote:
Of course, most of the other definitions of is a number that
have been posted may likewise fail (defined as not doing what the
OP would have wanted, in this case) with a numarray arange.
How about explicitly
Is there a good way to determine if an object is a numeric type?
Generally, I avoid type-checks in favor of try/except blocks, but I'm
not sure what to do in this case:
def f(i):
...
if x i:
...
The problem is, no error will be thrown if 'i' is, say, a string:
On Fri, 11 Feb 2005 12:11:44 -0700, Steven Bethard
[EMAIL PROTECTED] wrote:
Is there a good way to determine if an object is a numeric type?
Generally, I avoid type-checks in favor of try/except blocks, but I'm
not sure what to do in this case:
def f(i):
...
if x i:
Steven Bethard wrote:
Is there a good way to determine if an object is a numeric type?
Generally, I avoid type-checks in favor of try/except blocks, but I'm
not sure what to do in this case:
def f(i):
...
if x i:
...
The problem is, no error will be
Bill Mill wrote:
On Fri, 11 Feb 2005 12:11:44 -0700, Steven Bethard
[EMAIL PROTECTED] wrote:
Is there a good way to determine if an object is a numeric type?
How about:
if type(variable) == type(1):
print is an integer
else:
print please input an integer
This checks if it is an integer,
Dan Bishop wrote:
Steven Bethard wrote:
Is there a good way to determine if an object is a numeric type?
How about this?
... def is_number(x):
...try:
... x + 1
... return True
...except TypeError:
... return False
Great, thanks! That's the kind of thing I was looking
Steven Bethard [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Is there a good way to determine if an object is a numeric type?
Generally, I avoid type-checks in favor of try/except blocks, but I'm
not sure what to do in this case:
def f(i):
...
if x i:
Steven Bethard wrote:
Is there a good way to determine if an object is a numeric type? Generally, I
avoid type-checks in
favor of try/except blocks, but I'm not sure what to do in this case:
def f(i):
...
if x i:
...
The problem is, no error will be
As luck would have it, isnumber is a built-in Python function:
isnumber(1)
True
isnumber(1.0)
True
isnumber('1')
False
Michael
--
Michael D. Hartl, Ph.D.
Chief Technology Officer
http://quarksports.com/
--
http://mail.python.org/mailman/listinfo/python-list
George Sakkis wrote:
Steven Bethard [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
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):
...
29 matches
Mail list logo