显示调用栈的简化视图。
项目描述
显示调用栈
显示调用栈的简化视图。
此模块类似于Python内置的traceback
和inspect
模块,但更容易使用,并且显示更简单的输出。此模块在演示递归函数调用期间的调用栈时很有用。只需添加一行from showcallstack import showCallStack
,然后从您希望查看调用栈状态和每个调用帧中局部变量的位置调用showCallStack()
。
示例用法
此程序...
from showcallstack import showcallstack
def a():
varA = 42
b()
def b():
varB = 86
c()
def c():
varC = 99
showcallstack()
spam = 'SPAM!
a()
...输出如下
The call stack is 3 call(s) deep:
(Here is the "bottom" of the call stack.)
Local variables of call to a():
varA (type: int) == 42
Local variables of call to b():
varB (type: int) == 86
Local variables of call to c():
varC (type: int) == 99
(Here is the "top" of the call stack.)
Global variables:
spam (type: str) == 'SPAM!'
此递归阶乘程序...
from showcallstack import showcallstack
def factorial(num):
showcallstack()
if num == 1:
return 1
else:
return num * factorial(num - 1)
factorial(4)
...输出如下
The call stack is 1 call(s) deep:
(Here is the "bottom" of the call stack.)
Local variables of call to factorial():
num (type: int) == 4
(Here is the "top" of the call stack.)
Global variables:
No global variables.
The call stack is 2 call(s) deep:
(Here is the "bottom" of the call stack.)
Local variables of call to factorial():
num (type: int) == 4
Local variables of call to factorial():
num (type: int) == 3
(Here is the "top" of the call stack.)
Global variables:
No global variables.
The call stack is 3 call(s) deep:
(Here is the "bottom" of the call stack.)
Local variables of call to factorial():
num (type: int) == 4
Local variables of call to factorial():
num (type: int) == 3
Local variables of call to factorial():
num (type: int) == 2
(Here is the "top" of the call stack.)
Global variables:
No global variables.
The call stack is 4 call(s) deep:
(Here is the "bottom" of the call stack.)
Local variables of call to factorial():
num (type: int) == 4
Local variables of call to factorial():
num (type: int) == 3
Local variables of call to factorial():
num (type: int) == 2
Local variables of call to factorial():
num (type: int) == 1
(Here is the "top" of the call stack.)
Global variables:
No global variables.
您还可以调用showcallstack.getcallstack()
函数以获取作为字符串列表的输出。
支持
如果您发现此项目有帮助并希望支持其开发,请考虑在Patreon上向其创作者捐款。
项目详情
关闭
为 ShowCallStack-0.3.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 8f60b0145477af8a4a8486a9b47d9297028246ffc4f0e656d42e5b8ecc26cb71 |
|
MD5 | ddc64bcc71a2a0a275f8210e2ab68eca |
|
BLAKE2b-256 | 8b5de23ccbbb618c192a375c081580145efec7d965d8a2255a2e4169e8371d84 |