新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
python程序調(diào)試與c/c++的相關(guān)功能對比
python程序調(diào)試是很多程序員都在使用的。下面就向大家詳細(xì)的介紹下有關(guān)Python的相關(guān)知識。希望對大家有所幫助。python程序調(diào)試也可以實現(xiàn)類似于c/c++的單步調(diào)試功能,而 python 中的調(diào)試模塊 PDB 類似于c中的 GDB (常用命令等),可以進(jìn)行方便的調(diào)試。

下面是一個例子(debug_demo.py):
- #!/usr/bin/env python
- _debug = True
- def debug_demo(val):
- if _debug:
- import pdb
- pdb.set_trace() #引入相關(guān)的pdb模塊
- if val < 10:
- print "less than 10"
- elif val<20:
- print "less than 20, but big than 10"
- else:
- print "other condition"
在命令行中按如下方法進(jìn)行調(diào)試:
- python debug_demo.py
這時會進(jìn)入類似于gdb的界面,啟動相關(guān)的調(diào)試
- /home/tower/test/python/debug.py(9)debug_demo()
- -> if val <= 10:
- (Pdb)
可以輸入h來查看可用的命令集(很類似于gdb)。 單步調(diào)試對于某些情況下的調(diào)試是非常有幫助的
單步調(diào)試對于程序關(guān)鍵部分的邏輯跟蹤是很有意義的,所以 PDB 之于 python 類似于 GDB 之于C/C++. 但是相比于 GDB 而言, PDB 的功能還稍顯弱了許多, 所以還無法在 PDB里使用到 GDB 的所有feature. 可以預(yù)期的是隨著 python 轉(zhuǎn)至3.0及至后面的版本升級, PDB 也會愈發(fā)完善.值得期待.
網(wǎng)站欄目:python程序調(diào)試與c/c++的相關(guān)功能對比
網(wǎng)頁網(wǎng)址:http://m.fisionsoft.com.cn/article/dpgjdgj.html


咨詢
建站咨詢
