简体   繁体   中英

Get interim results of function calls while debugging Python in PyCharm

On breakpoints --> PyCharm debugger shows current list of variable states and is also able to show previous lines calculation/call results.

But what if I want to get interim results on function chain calls at the same line of code?

For example:

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)

Is it somehow possible in PyCharm?

This can be done by using a breakpoint on that line. Right click on the breakpoint and use a tuple in the Evalute and log field having as values the incremental method chain calls:

The following code shows differences in intermediate results:

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

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

Using a tuple in Evaluate and log :

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

The debugger shows the results on standard output:

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

Corresponding screenshot:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM