zoukankan      html  css  js  c++  java
  • python 调试

    python 调试基本和gdb调试一样,举例:

    debug .py

    1 #!/usr/bin/python  
    2 print "hello"
    3 
    4 i=0
    5 for j in range(10):
    6    i+=j
    7 print i

    调试命令:python -m pdb debug.py

              -m (mod)----- run library module as a script (terminates option list)

    pdb-----The Python Debugger

    常用命令说明:
    l #查看运行到哪行代码
    n #单步运行,跳过函数
    s #单步运行,可进入函数
    p 变量 #查看变量值
    b 行号 #断点设置到第几行
    b #显示所有断点列表
    cl 断点号 #删除某个断点
    cl #删除所有断点
    c #跳到下一个断点
    r #return当前函数

    a args 打印当前函数的参数
    exit(或者q) #退出


    更多的命令http://docs.python.org/library/pdb.html

    ming@ubuntu:~/python_test$ python -m pdb debug.py
    > /home/ming/python_test/debug.py(2)<module>()             #2意思是到2行
    -> print "hello"
    (Pdb) l

     1      #!/usr/bin/python
      2  ->    print "hello"                                      #->标记的意思是走到这一行,下次执行该行
      3      
      4      i=0
      5      for j in range(10):
      6         i+=j
      7      print i
    (Pdb) b 7
    Breakpoint 1 at /home/ming/python_test/debug.py:7
    (Pdb) c
    > /home/ming/python_test/debug.py(7)<module>()
    -> print i
    (Pdb) l
      2      print "hello"
      3      
      4      i=0
      5      for j in range(10):
      6         i+=j
      7 B->    print i
    [EOF]
    (Pdb) p i
    45
    (Pdb) n
    45
    --Return--                                                         #这里就结束了,return,但是不会退出,而是循环又开始了
    > /home/ming/python_test/debug.py(7)<module>()->None
    -> print i
    (Pdb)

    二。调试进阶和补充(暂时可能还用不到,不过先学习下)转自:http://www.open-open.com/lib/view/open1389595143289.html

  • 相关阅读:
    基于 mockm 的一款 HBuilderX 插件
    css 加载中省略号动画
    定时获取远程文件并存储更新记录
    跨域实例和解决方案
    接口数据总是返回 null 如何回馈和处理
    get 请求中如何携带 body 参数
    看起来像一个 textarea 的 div
    js 高精度运算
    nodejs 服务终端使用 nodemon 运行脚本时实时输出
    解决 vue-cli3 多入口打包 BASE_URL is not defined
  • 原文地址:https://www.cnblogs.com/zmlctt/p/3685962.html
Copyright © 2011-2022 走看看