Skip to Content
Modern Python Standard Library Cookbook
book

Modern Python Standard Library Cookbook

by Alessandro Molina
August 2018
Intermediate to advanced
366 pages
10h 14m
English
Packt Publishing
Content preview from Modern Python Standard Library Cookbook

How to do it...

If you want to stop code execution at a specific point and interactively move it forward while checking how your variables change and what flow the execution takes, you just want to set a tracing point where you want to stop, so that you will enter an interactive session in the shell where your code is running:

def divide(x, y):
    print('Going to divide {} / {}'.format(x, y))

    # Stop execution here and enter the debugger
    import pdb; pdb.set_trace()

    return x / y

Now, if we call the divide function, we will enter an interactive debugger that lets us see the value of x and y and move forward with the execution:

>>> print(divide(3, 2)) Going to divide 3 / 2 > ../sources/devtools/devtools_01.py(4)divide() -> return x / y (Pdb) x 3 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Matthew Wilkes

Publisher Resources

ISBN: 9781788830829Supplemental Content