Inserting a directive in the code to debug

For a long-running process, where the problem occurs much later in the program execution, it would be much more convenient to start the debugger within the program using the pdb set_trace() directive:

import pdb

class Pdb_test(object):
def __init__(self, parameter):
self.counter = parameter
def go(self):
for j in range(self.counter):
pdb.set_trace()
print ("--->",j)
return

if __name__ == '__main__':
Pdb_test(10).go()

set_trace() can be called at any point in the program to debug. For example, it can be called based on conditions, exception handlers, or a specific branch of control instructions.

In this case, the output is as follows: 

-> print ("--->",j)
(Pdb)

The code run stops, exactly after the pdb.set_trace() statement completes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.0.53