加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Debug函数的利器__pysnooper库.py 1.01 KB
一键复制 编辑 原始数据 按行查看 历史
fengmingshan 提交于 2021-12-15 20:46 . 找回资料提交
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 3 19:35:41 2018
@author: Administrator
"""
import pysnooper
import random
@pysnooper.snoop()
def number_to_bits(number):
if number:
bits = []
while number:
number, remainder = divmod(number, 2)
bits.insert(0, remainder)
return bits
else:
return [0]
number_to_bits(6)
def 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()
# 针对函数内出现循环,pysnooper也能展开到每一层循环:
@pysnooper.snoop()
def sum2(x):
for i in range(0,50,1):
x = x+i
print(x)
sum2(2)
def sum2(x,y):
for i in range(0,50,1):
z = x + y + i
print(z)
with pysnooper.snoop():
sum_xy = x + y
count = i
print(sum_xy, count)
sum2(1,2)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化