Reputation: 14685
traceback.format_exception()
takes three arguments.
sys.exc_info()
returns a tuple of three elements that are the required arguments for traceback.format_exception()
Is there any way of avoiding the two line "conversion":
a,b,c = sys.exc_info()
error_info = traceback.format_exception(a,b,c)
Clearly
error_info = traceback.format_exception(sys.exc_info())
doesn't work, because format_exception()
takes three arguments, not one tuple (facepalm!)
Is there some tidy way of doing this in one statement?
Upvotes: 0
Views: 109
Reputation: 23555
You can use the *
operator to unpack arguments from a list or tuple:
error_info = traceback.format_exception(*sys.exc_info())
Here's the example from the docs:
>>> range(3, 6) # normal call with separate arguments
[3, 4, 5]
>>> args = [3, 6]
>>> range(*args) # call with arguments unpacked from a list
[3, 4, 5]
Upvotes: 2