On Tue, Feb 5, 2013 at 11:04 PM, Steven D'Aprano
wrote:
> py> isinstance(NAN, Number)
> True
Does that line of code count as nerd humour?
ChrisA
--
http://mail.python.org/mailman/listinfo/python-list
Pete Forman wrote:
> Steven D'Aprano writes:
>>> I want to check that a value is a number. [...]
>> I'm leaning towards an isinstance check
[...]
> BTW what if the value is Not-a-Number? ;-)
Nothing different, and hopefully exactly what the caller expects. As far as
Python is concerned, NANs are
Steven D'Aprano writes:
>> I want to check that a value is a number. [...]
> I'm leaning towards an isinstance check
Well that is the answer to your question, whether the value *is* a
number. EAFP can answer the question whether the value *behaves* like a
number, where the criterion depends on wh
On 2/4/2013 6:16 PM, Steven D'Aprano wrote:
The eternal conflict between "Look Before You Leap" and "Easier to Ask for
Forgiveness than Permission" (LBYL vs EAFP) continues...
A somewhat different answer is that it depends on what you want the
function to do, as documented and *tested*. And th
On Tue, 05 Feb 2013 16:20:19 +1100, Chris Angelico wrote:
> On Tue, Feb 5, 2013 at 3:52 PM, Steven D'Aprano
> wrote:
>> There's also the principle that it is best to raise an exception as
>> early as possible. It's easier to track down errors at the point they
>> are introduced than long afterwar
On Mon, Feb 4, 2013 at 9:52 PM, Steven D'Aprano
wrote:
> You seem to be making the
> classic mistake of thinking that exceptions are something to avoid:
Far from it. You've extrapolated a lot more than what I actually
said, and I completely agree with everything you wrote. I was
explaining EAFP
On Tue, Feb 5, 2013 at 3:52 PM, Steven D'Aprano
wrote:
> There's also the principle that it is best to raise an exception as early
> as possible. It's easier to track down errors at the point they are
> introduced than long afterwards.
Yes, definitely, especially (as was mentioned) if you're work
On Tue, Feb 5, 2013 at 2:52 PM, Steven D'Aprano
wrote:
> On Tue, 05 Feb 2013 10:38:41 +1100, Chris Angelico wrote:
>
>> On Tue, Feb 5, 2013 at 10:16 AM, Steven D'Aprano
>> wrote:
>>> A third option is not to check x at all, and hope that it will blow up
>>> at some arbitrary place in the middle o
On Mon, 04 Feb 2013 16:46:11 -0700, Ian Kelly wrote:
> Presumably if the operation requires
> a number, then it will at some point perform some kind of numerical
> manipulation that will raise a TypeError if one is not passed. If the
> operation succeeds, then the object supported all the operatio
On Tue, 05 Feb 2013 10:38:41 +1100, Chris Angelico wrote:
> On Tue, Feb 5, 2013 at 10:16 AM, Steven D'Aprano
> wrote:
>> A third option is not to check x at all, and hope that it will blow up
>> at some arbitrary place in the middle of my code rather than silently
>> do the wrong thing. I don't l
On 4 February 2013 23:16, Steven D'Aprano
wrote:
>
> I want to check that a value is a number. Let's say I don't care what sort
> of number -- float, int, complex, Fraction, Decimal, something else -- just
> that it is a number. Should I:
>
> Look Before I Leap:
>
> from numbers import Number
On 02/04/2013 03:16 PM, Steven D'Aprano wrote:
The eternal conflict between "Look Before You Leap" and "Easier to Ask for
Forgiveness than Permission" (LBYL vs EAFP) continues...
I want to check that a value is a number. Let's say I don't care what sort
of number -- float, int, complex, Fraction
On Tue, Feb 5, 2013 at 10:16 AM, Steven D'Aprano
wrote:
> from numbers import Number
> if isinstance(x, Number):
> ...
> else:
> raise TypeError
>
>
> or Ask Forgiveness:
>
> x + 0
> ...
>
>
> where in both cases the ellipsis ... is the code I actually care abou
On 02/04/2013 06:38 PM, Chris Angelico wrote:
On Tue, Feb 5, 2013 at 10:16 AM, Steven D'Aprano
wrote:
A third option is not to check x at all, and hope that it will blow up at
some arbitrary place in the middle of my code rather than silently do the
wrong thing. I don't like this idea because,
On Feb 4, 2013 4:24 PM, "Steven D'Aprano" <
steve+comp.lang.pyt...@pearwood.info> wrote:
>
> The eternal conflict between "Look Before You Leap" and "Easier to Ask for
> Forgiveness than Permission" (LBYL vs EAFP) continues...
>
> I want to check that a value is a number. Let's say I don't care wha
On Tue, Feb 5, 2013 at 10:16 AM, Steven D'Aprano
wrote:
> A third option is not to check x at all, and hope that it will blow up at
> some arbitrary place in the middle of my code rather than silently do the
> wrong thing. I don't like this idea because, even if it fails, it is better
> to fail ea
16 matches
Mail list logo