【发布时间】:2020-11-20 18:21:19
【问题描述】:
我正在使用 VS code 的 Python 调试器来监控函数返回。
Python: 3.7.3
VS Code: 1.51.0
Python Extension: v2020.11.371526539
MACOS: 10.15.7 (19H2)
我可以在变量返回之前检查它们,它们是正确的,但是在返回之后,它们会假定以前保存的值 - 就像它们从未被 return 语句覆盖一样。
def align_bb(self, bbs2)
...
# the variables are correct at this point
return update_obj, new_obj, stale_obj
#but they change by the time they come back from the function
update_obj, new_obj, stale_obj = trk.align_bb(bbs2)
函数内部的参数值
update_obj, new_obj, stale_obj
([], [[...], [...], [...]], [0])
special variables
function variables
0:[]
1:[[10, 20, 80, 100], [80, 110, 90, 110], [80, 100, 10, 40]]
2:[0]
len():3
return语句后的参数值:
update_obj, new_obj, stale_obj
([], [[...]], [])
special variables
function variables
0:[]
1:[[35, 65, 35, 65]]
2:[]
len():3
如果我在调试器之外运行代码,返回值保持一致。我已经重新启动了 VS 代码和我的计算机。我还恢复了 python 扩展并卸载了它,但我每次都得到相同的奇怪值。我肯定是在函数返回之后查看值,而不是之前。
【问题讨论】:
-
你的代码是不是做错了,还是只是调试器显示问题?
-
似乎仅限于调试器。如果我运行
python tracker.py,返回是正确的。我也在调试控制台中获得了这些值