On Mon, 26 Jun 2017 02:40 am, Skip Montanaro wrote:
>> py> isinstance(KeyboardInterrupt(), Exception)
>> False
>> py> isinstance(ValueError, Exception)
>> False
>>
>
> I might have missed something, but don't you want to be using BaseException
> as your class/type?
Yes I do, which is why I was
On 06/25/17 12:10, Steve D'Aprano wrote:
py> isinstance(KeyboardInterrupt(), Exception)
False
py> isinstance(ValueError, Exception)
False
That's because KeyboardInterrupt is not a subclass of Exception. If you
want to catch that as well you need to check against BaseException.
https://docs.
>
> py> isinstance(KeyboardInterrupt(), Exception)
> False
> py> isinstance(ValueError, Exception)
> False
>
I might have missed something, but don't you want to be using BaseException
as your class/type? Also, Checking isinstance() between two classes isn't
likely to work, I don't think.
Both th
On Sun, 25 Jun 2017 05:50 pm, Paul Rubin wrote:
> Steve D'Aprano writes:
>> What's the right/best way to test whether an object is an exception
>> ahead of time? (That is, without trying to raise from it.)
>
> Maybe I'm missing something but
>isinstance(obj, Exception)
> seems to work.
Not
Steve D'Aprano writes:
> What's the right/best way to test whether an object is an exception
> ahead of time? (That is, without trying to raise from it.)
Maybe I'm missing something but
isinstance(obj, Exception)
seems to work.
--
https://mail.python.org/mailman/listinfo/python-list
On 25Jun2017 13:47, Ben Finney wrote:
Steve D'Aprano writes:
[…] the result of passing a non-exception to raise is to raise an
exception, so I cannot trivially distinguish between "caller passes an
exception" and "caller passes a non-exception" (result is still an
exception).
Yes, hence my c
Steve D'Aprano writes:
> […] the result of passing a non-exception to raise is to raise an
> exception, so I cannot trivially distinguish between "caller passes an
> exception" and "caller passes a non-exception" (result is still an
> exception).
Yes, hence my characterising this problem as the
On Sun, 25 Jun 2017 10:49 am, Ben Finney wrote:
> Steve D'Aprano writes:
>
>> What's the right/best way to test whether an object is an exception
>> ahead of time? (That is, without trying to raise from it.)
>
> This being Python, it is Easier to Ask for Forgiveness than for
> Permission.
Some
On Sun, 25 Jun 2017 09:37 am, Cameron Simpson wrote:
> On 24Jun2017 20:31, Steve D'Aprano wrote:
>>What's the right/best way to test whether an object is an exception ahead of
>>time? (That is, without trying to raise from it.)
>>
>>I have:
>>
>>return (isinstance(obj, type) and issubclass(obj, B
Steve D'Aprano writes:
> What's the right/best way to test whether an object is an exception
> ahead of time? (That is, without trying to raise from it.)
This being Python, it is Easier to Ask for Forgiveness than for
Permission.
The corollary of that is, if you try to ask permission first (to
On 24Jun2017 20:31, Steve D'Aprano wrote:
What's the right/best way to test whether an object is an exception ahead of
time? (That is, without trying to raise from it.)
I have:
return (isinstance(obj, type) and issubclass(obj, BaseException)
or isinstance(obj, BaseException))
I haven'
On Sat, 24 Jun 2017 09:23 pm, mbyrne...@gmail.com wrote:
> On Saturday, June 24, 2017 at 11:31:11 AM UTC+1, Steve D'Aprano wrote:
>> What's the right/best way to test whether an object is an exception ahead of
>> time? (That is, without trying to raise from it.)
>>
>> I have:
>>
>> return (isins
On Saturday, June 24, 2017 at 11:31:11 AM UTC+1, Steve D'Aprano wrote:
> What's the right/best way to test whether an object is an exception ahead of
> time? (That is, without trying to raise from it.)
>
> I have:
>
> return (isinstance(obj, type) and issubclass(obj, BaseException)
> or i
What's the right/best way to test whether an object is an exception ahead of
time? (That is, without trying to raise from it.)
I have:
return (isinstance(obj, type) and issubclass(obj, BaseException)
or isinstance(obj, BaseException))
Any better ideas?
--
Steve
“Cheer up,” they said
14 matches
Mail list logo