[筆記]Python的調試器pudb簡易教程


Linux下運行python腳本,pudb是一個不錯的調試器。

語法高亮,斷點,調用棧,命令行,都有了,如下圖。

 

 

[安裝]

pip install pudb

 

[使用]

pudb xxx.py

 

[快捷鍵]

 

最常用的快捷鍵,應該是如下幾個:

  • n - step over ("next") # 運行到下一行
  • s - step into # 運行進函數
  • c - continue # 繼續運行
  • r/f - finish current function # 結束當前函數
  • b - toggle breakpoint # 打斷點/取消斷點
  • V - focus variables # 聚焦在變量窗口
  • f1/?/H - show this help screen # 顯示幫助窗口
  • Ctrl-n/p - browse command line history # 瀏覽命令行歷史
  • t/r/s/c - show type/repr/str/custom for this variable # 切換type/repr/str/custom

界面下按?就能出來快捷鍵列表,如下:

                                                                                    
Welcome to PuDB, the Python Urwid debugger.                                           
-------------------------------------------                                           
                                                                                      
(This help screen is scrollable. Hit Page Down to see more.)                          
                                                                                      
Keys:                                                          # 快捷鍵相關
    Ctrl-p - edit preferences                                  # 編輯配置
                                                                                      
    n - step over ("next")                                     # 運行到下一行                       
    s - step into                                              # 運行進函數
    c - continue                                               # 繼續運行
    r/f - finish current function                              # 結束當前函數
    t - run to cursor                                          # 運行到光標處
    e - show traceback [post-mortem or in exception state]     # 顯示traceback

    H - move to current line (bottom of stack)                 # 移動到當前行(棧底)
    u - move up one stack frame                                # 移動到棧的上一行
    d - move down one stack frame                              # 移動到棧的下一行
                                                               
    o - show console/output screen                             # 顯示命令行屏幕(回車返回pudb)

    b - toggle breakpoint                                      # 打斷點/取消斷點
    m - open module                                            # 打開python模塊

    j/k - up/down                                              # 上/下
    Ctrl-u/d - page up/down                                    # 上一頁/下一頁
    h/l - scroll left/right                                    # 左滾動/右滾動
    g/G - start/end                                            # 跳轉到首行/末行
    L - show (file/line) location / go to line                 # 跳到指定行
    / - search                                                 # 查找
    ,/. - search next/previous                                 # 查找下一個/上一個

    V - focus variables                                        # 聚焦在變量窗口
    S - focus stack                                            # 聚焦在棧窗口
    B - focus breakpoint list                                  # 聚焦在斷點列表窗口
    C - focus code                                             # 聚焦在代碼窗口
                      
    f1/?/H - show this help screen                             # 顯示幫助窗口
    q - quit                                                   # 退出

    Ctrl-c - when in continue mode, break back to PuDB         # 當處於連續模式時,返回pudb

    Ctrl-l - redraw screen                                     # 重繪窗口
                                                                                      
Command line-related:                                          # 命令行相關
    ! - invoke configured python command line in current environment            # 進入命令行窗口
    Ctrl-x - toggle inline command line focus                                   # 切換命令行窗口和代碼窗口

    +/- - grow/shrink inline command line (active in command line history)      # 增長/縮減命令行(命令行歷史下激活)
    _/= - minimize/maximize inline command line (active in command line history)# 最小化/最大化命令行(命令行歷史下激活)
                                                                                      
    Ctrl-v - insert newline                                    # 插入新行
    Ctrl-n/p - browse command line history                     # 瀏覽命令行歷史
    Tab - yes, there is (simple) tab completion                # 快速補齊

Sidebar-related (active in sidebar):                           # 工具欄相關(工具欄激活時有效)
    +/- - grow/shrink sidebar                                  # 擴大/縮減工具欄(指的是工具欄寬度)
    _/= - minimize/maximize sidebar                            # 最小化/最大化工具欄
    [/] - grow/shrink relative size of active sidebar box      # 擴大/縮減激活工具欄相對大小(指的是窗口高度)
                  
Keys in variables list:                                        # 變量列表窗口的快捷鍵
    \ - expand/collapse                                        # 展開/收縮
    t/r/s/c - show type/repr/str/custom for this variable      # 切換type/repr/str/custom
    h - toggle highlighting                                    # 切換高亮
    @ - toggle repetition at top                               # 切換頂部重復
    * - cycle attribute visibility: public/_private/__dunder__ # 屬性的循環可視化
    m - toggle method visibility                               # 切換方法的可見性
    w - toggle line wrapping                                   # 切換換行
    n/insert - add new watch expression                        # 添加新的watch表達式
    enter - edit options (also to delete)                      # 編輯選項

Keys in stack list:                                            # 棧列表窗口的快捷鍵

    enter - jump to frame                                      # 跳到某幀

Keys in breakpoints view:                                      # 斷點列表窗口的快捷鍵

    enter - edit breakpoint                                    # 編輯斷點
    d - delete breakpoint                                      # 刪除斷點
    e - enable/disable breakpoint                              # 啟用/禁用斷點
                                          

當你不知道如何點中OK鍵時,試試移動上下左右的箭頭鍵,Enjoy it :)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM