推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
xinali
V2EX  ›  Python

python 代码调试

  •  
  •   xinali · Aug 3, 2016 · 3170 views
    This topic created in 3705 days ago, the information mentioned may be changed or developed.

    现在有个需求, python 文件中的变量可以跟 ipython 交互,可以有两种方式达到需求

    1. 在 python 中嵌入相关 ipython 代码,执行到特定语句时,进入 ipython ,之后可以访问文件已经执行的变量
    2. 直接在 ipython 中运行文件,执行结束后, ipython 可以访问文件中的变量

    有什么办法可以达到上面任意一个条件,从而满足要求吗?

    7 replies  •  2016-08-04 13:43:27 +08:00
    eriale
        1
    eriale  
       Aug 3, 2016
    试试 ipdb
    XYxe
        2
    XYxe  
       Aug 3, 2016 via Android
    from IPython import embed

    embed()
    C0VN
        3
    C0VN  
       Aug 3, 2016
    import ipdb
    ipdb.set_trace()
    liyj144
        4
    liyj144  
       Aug 3, 2016
    也可以试试 pudb , pdb 升级版
    vinceguo
        5
    vinceguo  
       Aug 3, 2016 via Android
    既然用 ipython ,就看看 ipython 的文档。
    ipython 有 magic function 可以做到第二条,不过我不告诉你是哪一个。去 RTFM 吧, ipython 有很多很有用的奇技淫巧,不会让你失望的

    长这么大还没用过 pdb ,好像不需要啊哈哈
    czheo
        6
    czheo  
       Aug 3, 2016
    ipython 里输入 %run [your_file].py
    xiongbiao
        7
    xiongbiao  
       Aug 4, 2016
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2632 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 09:00 · PVG 17:00 · LAX 02:00 · JFK 05:00
    ♥ Do have faith in what you're doing.