Python uplift with two parameters

What does it do raise A, B? And how does he differ from what he does raise A?

Some examples (works on python 2.7 interpreter):

class E(Exception):
    pass
e = E()

raise Exception, e
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
__main__.E

raise Exception(e)
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
Exception

raise (Exception, e)
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
Exception

Thank!

+4
source share
1 answer

raisesupports up to three arguments; the first two are the type and value, the third is the trace object to use for exclusion. Line:

raise Exception, value

usually exactly equivalent:

raise Exception(value)

therefore, we create an instance Exception()by passing the second value as an argument to the exception constructor.

, , E, Exception , , :

raise Exception, e

:

raise e

:

raise E, ()

None:

raise E, None

E ; , E; None raise E().

, raise Exception Python , .

raise:

, . : , . , ; None, , . , , .

, , . , raise Python 3, . PEP 3109 - Python 3000.

+8

Source: https://habr.com/ru/post/1535430/


All Articles