Re: is parameter an iterable?
- From: "Fredrik Lundh" <fredrik@xxxxxxxxxxxxxx>
- Date: Wed, 16 Nov 2005 17:39:57 +0100
Rick Wotnaz wrote.
> ... which leads me to belive that 'msg' is not type(str). It can be
> coerced (str(msg).find works as expected). But what exactly is msg?
> It appears to be of <type 'instance'>, and does not test equal to a
> string.
it's an instance of the exception type, of course.
:::
if you do
raise SomeError, value
Python will actually do
raise SomeError(value)
(that is, create a SomeError exception and pass the value as its
first argument).
you can use either form in your code (I prefer the latter myself).
:::
as for catching the exceptions, if you do
try:
...
except SomeError, v:
...
Python will treat this as
try:
...
except:
# some exception occurred
typ = sys.exc_type
exc = sys.exc_value
if issubclass(typ, SomeError):
v = exc
...
else:
raise # propagate!
(where typ and exc are internal variables)
</F>
.
- Follow-Ups:
- Re: is parameter an iterable?
- From: Bengt Richter
- Re: is parameter an iterable?
- From: Rick Wotnaz
- Re: is parameter an iterable?
- References:
- is parameter an iterable?
- From: py
- Re: is parameter an iterable?
- From: Dan Sommers
- Re: is parameter an iterable?
- From: py
- Re: is parameter an iterable?
- From: Steven D'Aprano
- Re: is parameter an iterable?
- From: Rick Wotnaz
- is parameter an iterable?
- Prev by Date: Re: Script to export MySQL tables to csv
- Next by Date: Re: A way for closing an app monitor
- Previous by thread: Re: is parameter an iterable?
- Next by thread: Re: is parameter an iterable?
- Index(es):
Relevant Pages
|