调试程序时,很多人喜欢直接用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

 

相关文章:

  • 2021-07-30
  • 2021-10-24
  • 2021-11-23
  • 2021-08-08
  • 2022-01-06
  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-20
  • 2021-09-10
  • 2021-12-29
  • 2021-11-16
  • 2021-04-04
  • 2021-11-07
相关资源
相似解决方案