pdb/ipdb for python break on editable condition

前端 未结 3 1825
忘掉有多难
忘掉有多难 2020-12-25 13:13

Say I have code the following code:

for i in range(100):
    print i

In general I can add one line to the code as:

for i in         


        
3条回答
  •  情深已故
    2020-12-25 13:39

    I did some exploration myself, here is my new understanding of pdb.

    When you input import ipdb;ipdb.set_trace() you actually add an entry point of ipdb to the line, not really a breakpoint.

    After you enter ipdb, you can then set up breakpoints.

    So, to realize what I want for conditional debugging, I should do this:

    import ipdb;ipdb.set_trace()
    for i in range(100):
        print i
    

    then after I enter ipdb, I can input b xx, i == 10, and then c or r to run the code. The code will stop when the condition is met.

    When I input l, the bpnumber is shown for the line as :

              xx-1                  for i in range(100): 
    bpnumber> xx                        print i
              xx+1                      ...
    

    I have to say, the documentation and all other explanations are very confusing, I hope my answer here clarifies the difference between the "debug entry point" and "debug breakpoint"

提交回复
热议问题