在 PyCharm 中调试 Python 时获取函数调用的临时结果

Get interim results of function calls while debugging Python in PyCharm

On breakpoints --> PyCharm debugger 显示当前变量状态列表 and 也能显示之前的行calculation/call 个结果。

但是如果我想在同一行代码中获得函数链调用的中间结果怎么办?

例如:

l = [3, 4, 5]
l = list(map(str, l)) #here I want to check result "of map(str, l)"

s = "_".join(l).upper()[::-1] #here I want see values for each interim func calls (join, upper)

在 PyCharm 中是否有可能?

这可以通过在该行上使用断点来完成。右键单击断点并在 Evalute and log 字段中使用一个元组,该字段具有增量方法链调用的值:

以下代码显示了中间结果的差异:

l = ['Hello', 'my', 'friends']

s = "_".join(l).upper()[::-1]

Evaluate and log中使用一个元组:

(l, "_".join(l), "_".join(l).upper(), "_".join(l).upper()[::-1])

调试器在标准输出上显示结果:

(['Hello', 'my', 'friends'], 'Hello_my_friends', 'HELLO_MY_FRIENDS', 'SDNEIRF_YM_OLLEH')

对应截图: