網站首頁 編程語言 正文
pdb 使用方法
1. 常用命令
a. 斷點設置
b(reak)
[([filename:]lineno | function) [, condition]]
如果帶有 lineno 參數,則在當前文件相應行處設置一個斷點。如果帶有 function 參數,則在該函數的第一條可執行語句處設置一個斷點。行號可以加上文件名和冒號作為前綴,以在另一個文件(可能是尚未加載的文件)中設置一個斷點。另一個文件將在 sys.path
范圍內搜索。請注意,每個斷點都分配有一個編號,其他所有斷點命令都引用該編號。
如果第二個參數存在,它應該是一個表達式,且它的計算值為 true 時斷點才起作用。
如果不帶參數執行,將列出所有中斷,包括每個斷點、命中該斷點的次數、當前的忽略次數以及關聯的條件(如果有)。
tbreak
[([filename:]lineno | function) [, condition]]
臨時斷點,在第一次命中時會自動刪除。它的參數與 break
相同。
cl(ear)
[filename:lineno | bpnumber …]
如果參數是 filename:lineno,則清除此行上的所有斷點。如果參數是空格分隔的斷點編號列表,則清除這些斷點。如果不帶參數,則清除所有斷點(但會先提示確認)。
b. 運行
n(ext)
繼續運行,直到運行到當前函數的下一行,或當前函數返回為止。( next
和 step
之間的區別在于,step
進入被調用函數內部并停止,而 next
(幾乎)全速運行被調用函數,僅在當前函數的下一行停止。)
s(tep)
運行當前行,在第一個可以停止的位置(在被調用的函數內部或在當前函數的下一行)停下。
c(ont(inue))
繼續運行,僅在遇到斷點時停止。
r(eturn)
繼續運行,直到當前函數返回。
c. 查看
p expression
在當前上下文中運行 expression 并打印它的值。
print() 也可以使用,但它不是一個調試器命令 — 它執行 Python print()
函數。
pp expression
與 p
命令類似,但表達式的值使用 pprint
模塊美觀地打印。
d. 其他
h(elp)
[command]
不帶參數時,顯示可用的命令列表。參數為 command 時,打印有關該命令的幫助。help pdb
顯示完整文檔(即 pdb
模塊的文檔字符串)。由于 command 參數必須是標識符,因此要獲取 !
的幫助必須輸入 help exec
。
q(uit)
退出調試器。 被執行的程序將被中止。
2. 使用方法一
python3 -m pdb test.py
這里程序來自于 無重復字符的最長子串 。
def lengthOfLongestSubstring(s: str) -> int: st = set() n = len(s) right, result = -1, 0 for left in range(n): if left!=0: st.remove(s[left - 1]) while right + 1 < n and s[right + 1] not in st: st.add(s[right + 1]) right += 1 result = max(result, right - left + 1) return result if __name__=='__main__': print(lengthOfLongestSubstring("abcabcbb"))
輸入 python3 -m pdb test.py
會自動停在第一行
(base) cilinyan@amax:~/clyan/xshell$ python3 -m pdb test.py > /data2/cilinyan/clyan/xshell/test.py(1)<module>() -> def lengthOfLongestSubstring(s: str) -> int:
以下是 python3 -m pdb test.py
的一些使用過程:
(base) cilinyan@amax:~/clyan/xshell$ python3 -m pdb test.py > /data2/cilinyan/clyan/xshell/test.py(1)<module>() -> def lengthOfLongestSubstring(s: str) -> int: (Pdb) ll 1 -> def lengthOfLongestSubstring(s: str) -> int: 2 st = set() 3 n = len(s) 4 right, result = -1, 0 5 for left in range(n): 6 if left!=0: st.remove(s[left - 1]) 7 while right + 1 < n and s[right + 1] not in st: 8 st.add(s[right + 1]) 9 right += 1 10 result = max(result, right - left + 1) 11 return result 12 13 if __name__=='__main__': 14 print(lengthOfLongestSubstring("abcabcbb")) (Pdb) b 5 Breakpoint 1 at /data2/cilinyan/clyan/xshell/test.py:5 (Pdb) ll 1 def lengthOfLongestSubstring(s: str) -> int: 2 st = set() 3 n = len(s) 4 right, result = -1, 0 5 B-> for left in range(n): 6 if left!=0: st.remove(s[left - 1]) 7 while right + 1 < n and s[right + 1] not in st: 8 st.add(s[right + 1]) 9 right += 1 10 result = max(result, right - left + 1) 11 return result (Pdb) p right -1 (Pdb) p s 'abcabcbb'
3. 使用方法二
import pdb; pdb.set_trace()
這里程序來自于 無重復字符的最長子串 。
import pdb def lengthOfLongestSubstring(s: str) -> int: st = set() n = len(s) right, result = -1, 0 pdb.set_trace() for left in range(n): if left!=0: st.remove(s[left - 1]) while right + 1 < n and s[right + 1] not in st: st.add(s[right + 1]) right += 1 result = max(result, right - left + 1) pdb.set_trace() return result if __name__=='__main__': print(lengthOfLongestSubstring("abcabcbb"))
輸入 python test.py
會自動設置 pdb.set_trace()
的下一行,以下是一些使用過程:
(base) cilinyan@amax:~/clyan/xshell$ python test.py > /data2/cilinyan/clyan/xshell/test.py(8)lengthOfLongestSubstring() -> for left in range(n): (Pdb) n > /data2/cilinyan/clyan/xshell/test.py(9)lengthOfLongestSubstring() -> if left!=0: st.remove(s[left - 1]) (Pdb) n > /data2/cilinyan/clyan/xshell/test.py(10)lengthOfLongestSubstring() -> while right + 1 < n and s[right + 1] not in st: (Pdb) c > /data2/cilinyan/clyan/xshell/test.py(15)lengthOfLongestSubstring() -> return result (Pdb) c 3 (base) cilinyan@amax:~/clyan/xshell$
原文鏈接:https://blog.csdn.net/weixin_43791477/article/details/125238550
相關推薦
- 2022-10-11 錯誤連接數據庫 [xxx] : org.pentaho.di.core.exception.Kett
- 2023-03-22 go?install和go?get的區別實例詳解_Golang
- 2023-07-08 echarts多個series進行自定義tooltip的數據顯示
- 2022-06-01 Python使用xlrd和xlwt批量讀寫excel文件的示例代碼_python
- 2022-08-17 Python字典查找數據的5個基礎操作方法_python
- 2023-10-09 mobx中react的觀察者
- 2022-02-28 ts-node : 無法加載文件 C:\Users\Dell\AppData\Roaming\npm
- 2022-10-02 關于react?useState更新異步問題_React
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支