Use IPython magic functions in ipdb shell

前端 未结 2 972
醉酒成梦
醉酒成梦 2021-01-30 22:53

When debugging Python script using ipdb my_script.py, I want to use IPython magic functions like %paste, %cd in ipdb debug se

2条回答
  •  花落未央
    2021-01-30 23:37

    You can open a IPython shell inside a stack, just like pdb does. Do the following:

    • Import embed() from IPython, and put it inside your code.
    • Run the script

    Example:

    from IPython import embed
    
    def some_func():
        i = 0
        embed()
        return 0
    

    In Python shell:

    >>> te.func()
    
    IPython 1.0.0 -- An enhanced Interactive Python.
    (...)
    
    In [1]: %whos
    
    Variable   Type    Data/Info
    i          int     0
    
    In [2]:
    

    Was that what you were looking for?

提交回复
热议问题