PySnooper¶
Github:https://github.com/lotapp/PySnooper
pip install pysnooper
使用:分析整个代码
@pysnooper.snoop()
def avg(args):
return sum(args) / len(args)
PS:调试代码片段
with pysnooper.snoop():
code
In [1]:
import functools
import pysnooper
# 分析整个代码
@pysnooper.snoop()
def sum(args):
return functools.reduce(lambda x, y: x + y, args)
def avg(args):
# return sum(args) / len(args)
sum_num = sum(args)
# 分析片段代码
with pysnooper.snoop():
avg_num = sum_num / len(args)
return avg_num
In [2]:
# 求和
sum(list(range(1, 101)))
Out[2]:
In [3]:
# 平均值
avg(list(range(1, 101)))
Out[3]: