python语法raise A, L有什么用?
What's the use of python syntax raise A, L?
如果调用下面的代码,其中L是一个列表,L是如何使用的?
raise A, L
请注意,此语法仅在 Python 2 中可用。Python 3 具有 lib2to3/fixes/fix_raise.py
在其 2 对 3 翻译系统中,该系统以以下文档字符串开头,为您提供有关文档保持沉默 (AFAIK) 的提示:
Fixer for 'raise E, V, T'
raise -> raise
raise E -> raise E
raise E, V -> raise E(V)
raise E, V, T -> raise E(V).with_traceback(T)
raise E, None, T -> raise E.with_traceback(T)
raise (((E, E'), E''), E'''), V -> raise E(V)
raise "foo", V, T -> warns about string exceptions
CAVEATS:
1) "raise E, V" will be incorrectly translated if V is an exception
instance. The correct Python 3 idiom is
raise E from V
but since we can't detect instance-hood by syntax alone and since
any client code would have to be changed as well, we don't automate
this.
归结起来就是raise FooException, [1, 2]
等价于raise FooException([1, 2])
;但你应该总是使用后者。
如果调用下面的代码,其中L是一个列表,L是如何使用的?
raise A, L
请注意,此语法仅在 Python 2 中可用。Python 3 具有 lib2to3/fixes/fix_raise.py
在其 2 对 3 翻译系统中,该系统以以下文档字符串开头,为您提供有关文档保持沉默 (AFAIK) 的提示:
Fixer for 'raise E, V, T'
raise -> raise
raise E -> raise E
raise E, V -> raise E(V)
raise E, V, T -> raise E(V).with_traceback(T)
raise E, None, T -> raise E.with_traceback(T)
raise (((E, E'), E''), E'''), V -> raise E(V)
raise "foo", V, T -> warns about string exceptions
CAVEATS:
1) "raise E, V" will be incorrectly translated if V is an exception
instance. The correct Python 3 idiom is
raise E from V
but since we can't detect instance-hood by syntax alone and since
any client code would have to be changed as well, we don't automate
this.
归结起来就是raise FooException, [1, 2]
等价于raise FooException([1, 2])
;但你应该总是使用后者。