The print_stack() function does actually print the stack (to stdout), not return it. What we want to do here is use format_stack so that we can include the stack in the message.
>>> import traceback
>>> value = traceback.print_stack()
File "<stdin>", line 1, in <module>
>>> print value
None
>>> value = traceback.format_stack()
>>> print value
[' File "<stdin>", line 1, in <module>\n']
The
print_stack()
function does actually print the stack (to stdout), not return it. What we want to do here is useformat_stack
so that we can include the stack in the message.