Python模块之pysnooper

调试程序时,很多人喜欢直接用print来代替断点调试,而pysnooper模块比print更方便,以装饰器的形式存在

安装pysnooper模块

pip3 install pysnooper

具体使用

import pysnooper

@pysnooper.snoop()
def test():
a = 100*1
sum=0
for i in range(10):
sum +=i
sum2 = sum +a
return sum2

if __name__ == ‘__main__‘:
test()

具体值的传递

output=‘a.txt‘        #将结果保存到文件a.txt
variables=(‘a‘)     #打印非局部变量a的值
depth=1             #Show snoop lines for functions that your function calls
prefix=‘hello‘      #在每一行打印信息前添加hello