How can I start the python console within a program (for easy debugging)?

前端 未结 6 1642
说谎
说谎 2021-02-10 03:52

After years of research programming in Matlab, I miss the way I could pause a program mid-execution and inspect the variables, do plotting, save/modify data, etc. via the intera

6条回答
  •  情歌与酒
    2021-02-10 04:41

    Use the pdb library.

    I have this line bound to in Vim:

    import pdb; pdb.set_trace()
    

    That will drop you into a pdb console.

    The pdb console isn't quite the same as the standard Python console… But it will do most of the same stuff. Also, in my ~/.pdbrc, I've got:

    alias i from IPython.Shell import IPShellEmbed as IPSh; IPSh(argv='')()
    

    So that I can get into a "real" iPython shell from pdb with the i command:

    (pdb) i
    ...
    In [1]:
    

提交回复
热议问题