V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
ikbear
V2EX  ›  Python

你是怎么调试Python代码的?

  •  
  •   ikbear ·
    ikbear · 2011-07-08 18:55:21 +08:00 · 6238 次点击
    这是一个创建于 4686 天前的主题,其中的信息可能已经有所发展或是发生改变。
    特别是只用VIM这种文本编辑器写代码的条件下,你是怎么调试Python代码的?
    12 条回复    1970-01-01 08:00:00 +08:00
    c
        1
    c  
       2011-07-08 19:04:25 +08:00
    logging & print
    ikbear
        2
    ikbear  
    OP
       2011-07-08 19:06:29 +08:00   ❤️ 1
    ikbear
        3
    ikbear  
    OP
       2011-07-08 19:10:28 +08:00
    看来是这里的howto入门更简单点http://docs.python.org/howto/logging.html
    reorx
        4
    reorx  
       2011-07-08 20:29:27 +08:00
    ikbear
        5
    ikbear  
    OP
       2011-07-08 20:38:58 +08:00
    @reorx 谢谢~
    qichangxing
        6
    qichangxing  
       2011-07-09 04:27:03 +08:00
    刷页面,看 Bug 信息。
    看控制台出错代码。
    shawiz
        7
    shawiz  
       2011-07-09 04:51:52 +08:00
    import pdb; pdb.set_trace()
    qichangxing
        8
    qichangxing  
       2011-07-11 04:34:05 +08:00
    以打印日志为荣 , 以单步跟踪为耻;
    以单元测试为荣 , 以人工测试为耻;
    ---
    Python 八荣八耻 http://wiki.woodpecker.org.cn/moin/
    blackbird
        9
    blackbird  
       2011-07-11 07:23:31 +08:00
    例如有一个数十个模块1000行以上的文本处理代码,
    比起对照日志,用调试器跟踪肯定更方便。
    sqbing
        10
    sqbing  
       2011-07-18 00:13:16 +08:00
    打日志,难道还有别的?
    est
        11
    est  
       2011-07-18 01:07:10 +08:00
    python -i
    dreampuf
        12
    dreampuf  
       2011-07-18 02:18:16 +08:00
    logging & unittest 与 debug 结合.
    何时使用看具体情况,如果新环境调试什么的,debug非常便捷.但是debug是打水漂,每次投入精力后并不能复用.
    而logging&unittest则是"为你的未来投资".复用,简单,清晰,而且可以递增.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2721 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 15:30 · PVG 23:30 · LAX 08:30 · JFK 11:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.