pysnooper pysnooper是一款python的debugger,该项目的创立口号是 Never use print for debugging again (永远不要使用print来debug??,相信大家也都深有体会了吧)。比起传统的pdb,这款debugger的特点在于可以一次性的分析一段代码的输出。是一种不错的选择,以下是实际的输出样例:
import pysnooperimport randomdef foo(): lst = [] for i in range(10): lst.append(random.randrange(1, 1000)) with pysnooper.snoop(): lower = min(lst) upper = max(lst) mid = (lower + upper) / 2 print(lower, mid, upper)foo()which outputs something like:New var:....... i = 9New var:....... lst = [681, 267, 74, 832, 284, 678, ...]09:37:35.881721 line 10 lower = min(lst)New var:....... lower = 7409:37:35.882137 line 11 upper = max(lst)New var:....... upper = 83209:37:35.882304 line 12 mid = (lower + upper) / 274 453.0 832New var:....... mid = 453.009:37:35.882486 line 13 print(lower, mid, upper)