当前位置:首页 >> 中药常识 >> 一行代码逃跑 debug 和 print,助力算法学习

一行代码逃跑 debug 和 print,助力算法学习

发布时间:2024-10-20

fix(strs):

解释器结果:

watch 和 watch_explode

watch 用来另设监控的非局部常量,watch_explode 暗示另设的常量都不管控,只管控没另设的常量,正好和 watch 意味著。

index = 1

@pysnooper.snoop(watch=('index'))

def longestCommonPrefix(strs):

解释器结果

从未加 watch 变量

Starting var:.. strs = ['flower', 'flow', 'flight']

00:12:33.715367 call 5 def longestCommonPrefix(strs):

00:12:33.717324 line 7 res = ''

New var:....... res = ''

加了watch 变量,就会有一个 Starting var:.. index

Starting var:.. strs = ['flower', 'flow', 'flight']

Starting var:.. index = 1

00:10:35.151036 call 5 def longestCommonPrefix(strs):

00:10:35.151288 line 7 res = ''

New var:....... res = ''

depth

depth 管控formula_的深度

@pysnooper.snoop(depth=2)

def longestCommonPrefix(strs):

otherMethod()

解释器结果

Starting var:.. strs = ['flower', 'flow', 'flight']

00:20:54.059803 call 5 def longestCommonPrefix(strs):

00:20:54.059803 line 6 otherMethod()

00:20:54.060785 call 16 def otherMethod():

00:20:54.060785 line 17 x = 1

New var:....... x = 1

00:20:54.060785 line 18 x = x + 1

Modified var:.. x = 2

00:20:54.060785 return 18 x = x + 1

Return value:.. None

00:20:54.061782 line 7 res = ''

管控的结果表明,当管控到命令行的formula_的时候,记录上会以致于缩进,并将它的局部常量和返回值复印机处置。

prefix

prefix 控制器章节的前缀

@pysnooper.snoop(prefix='-------------')

def longestCommonPrefix(strs):

解释器结果

-------------Starting var:.. strs = ['flower', 'flow', 'flight']

-------------00:39:13.986741 call 5 def longestCommonPrefix(strs):

-------------00:39:13.987218 line 6 res = ''

relative_time

relative_time 文档运转的整整

@pysnooper.snoop(relative_time=True)

def longestCommonPrefix(strs):

解释器结果

Starting var:.. strs = ['flower', 'flow', 'flight']

00:00:00.000000 call 5 def longestCommonPrefix(strs):

00:00:00.001998 line 6 res = ''

New var:....... res = ''

00:00:00.001998 line 7 for i in zip(*strs):

max_variable_length

max_variable_length 控制器的常量和出现异常的仅有长度,选项是 100 个位,超过 100 个位就会被截断,可以另设为 max_variable_length=None 不截断控制器

@pysnooper.snoop(max_variable_length=5)

def longestCommonPrefix(strs):

解释器结果

Starting var:.. strs = [...]

00:56:44.343639 call 5 def longestCommonPrefix(strs):

00:56:44.344696 line 6 res = ''

New var:....... res = ''

00:56:44.344696 line 7 for i in zip(*strs):

New var:....... i = (...)

概括

本文介绍了怎么应用于 pysnooper 工具,pysnooper 不仅可以少一些 debug 和 print,更能帮助理解迭代题名。

广州医院挂号
北京哪里治疗眼科好
西安皮肤病医院电话
食物寒凉引起肠胃不适怎么缓解好?
腹泻吃妈咪爱还是新必奇蒙脱石散比较好
吃火锅肚子痛缓解方法
来氟米特片副作用
长期熬夜精力透支怎么缓解
标签:
友情链接: