Enter Interactive Mode In Python

后端 未结 7 819
日久生厌
日久生厌 2021-01-30 06:42

I\'m running my Python program and have a point where it would be useful to jump in and see what\'s going on, and then step out again. Sort of like a temporary console mode.

7条回答
  •  旧巷少年郎
    2021-01-30 06:55

    From Python 3.7 onwards, you can also use breakpoint() to get into the debugger, e.g.:

    for thing in set_of_things:
        breakpoint()
        do_stuff_to(thing)
    

    This is a little easier to remember and write, and will open your code in pdb by default.

    However, it's also possible to set the PYTHONBREAKPOINT environment to the name of a callable, which could be another debugger such as pudb or ipdb, or it could be IPython's embed, or anything else.

提交回复
热议问题