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 :)