在 Python 中也可以像 gcc/gdb 那样调试程序,只要在运行 Python 程序时引入 pdb 模块(假设要调试的程序名为 d.py):
代码如下:
$ vi d.py
#!/usr/bin/python
def main():
i, sum = 1, 0
for i in xrange(100):
sum = sum + i
print sum
if __name__ == '__main__':
main()
$ python -m pdb d.py
运行上面的命令后进入以下界面,可以输入类似 gdb 的命令来改变程序的执行流程:
代码如下:
$ python -m pdb 1.py
> d.py(3)()
-> def main():
(Pdb)
list 显示程序的最近代码段:
代码如下:
(Pdb) list
1 #!/usr/bin/python
2
3 -> def main():
4 i, sum = 1, 0
5 for i in xrange(100):
6 sum = sum + i
7 print sum
8
9 if __name__ == '__main__':
10 main()
[EOF]
next 或者 n 执行下一行代码:
代码如下:
(Pdb) next
> d.py(9)()
-> if __name__ == '__main__':
用 break 在第6行设置一个断点:
代码如下:
(Pdb) break d.py:6
Breakpoint 1 at d.py:6
(Pdb) list
1 #!/usr/bin/python
2
3 def main():
4 i, sum = 1, 0
5 -> for i in xrange(100):
6 B sum = sum + i
7 print sum
8
9 if __name__ == '__main__':
10 main()
[EOF]
如果想在函数处设置断点:
代码如下:
(Pdb) break d.main
d.py:3
(Pdb) list
1 #!/usr/bin/python
2
3 B def main():
4 -> i, sum = 1, 0
5 for i in xrange(100):
6 sum = sum + i
7 print sum
8
9 if __name__ == '__main__':
10 main()
[EOF]
还可以给断点加条件,比如设置条件只有当 sum > 50 的时候才 break:
代码如下:
(Pdb) break d.py:6, sum > 50
Breakpoint 1 at d.py:6
如果想查看某个变量的值,可以用 pp 命令打印出来:
代码如下:
(Pdb) step
> d.py(5)main()
-> for i in xrange(100):
(Pdb) pp sum
0
可以直接在程序里使用 pdb 模块,import pdb 后 pdb.set_trace():
代码如下:
#!/usr/bin/python
import pdb
def main():
i, sum = 1, 0
for i in xrange(100):
sum = sum + i
pdb.set_trace()
print sum
if __name__ == '__main__':
main()
这样只要运行程序 ./d.py 就可以直接运行到 print sum 处:
代码如下:
$ ./d.py
> d.py(9)main()
-> print sum
(Pdb)
总结

Pythonarrayssupportvariousoperations:1)Slicingextractssubsets,2)Appending/Extendingaddselements,3)Insertingplaceselementsatspecificpositions,4)Removingdeleteselements,5)Sorting/Reversingchangesorder,and6)Listcomprehensionscreatenewlistsbasedonexistin

NumPyarraysareessentialforapplicationsrequiringefficientnumericalcomputationsanddatamanipulation.Theyarecrucialindatascience,machinelearning,physics,engineering,andfinanceduetotheirabilitytohandlelarge-scaledataefficiently.Forexample,infinancialanaly

useanArray.ArarayoveralistinpythonwhendeAlingwithHomoGeneData,performance-Caliticalcode,orinterfacingwithccode.1)同質性data:arraysSaveMemorywithTypedElements.2)績效code-performance-calitialcode-calliginal-clitical-clitical-calligation-Critical-Code:Arraysofferferbetterperbetterperperformanceformanceformancefornallancefornalumericalical.3)

不,notalllistoperationsareSupportedByArrays,andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorinsertwithoutresizing,wheremactsperformance.2)listssdonotguaranteeconecontanttanttanttanttanttanttanttanttanttimecomplecomecomplecomecomecomecomecomecomplecomectacccesslectaccesslecrectaccesslerikearraysodo。

toAccesselementsInapythonlist,useIndIndexing,負索引,切片,口頭化。 1)indexingStartSat0.2)否定indexingAccessesessessessesfomtheend.3)slicingextractsportions.4)iterationerationUsistorationUsisturessoreTionsforloopsoreNumeratorseforeporloopsorenumerate.alwaysCheckListListListListlentePtotoVoidToavoIndexIndexIndexIndexIndexIndExerror。

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通過使用pyenv、venv和Anaconda來管理不同的Python版本。 1)使用pyenv管理多個Python版本:安裝pyenv,設置全局和本地版本。 2)使用venv創建虛擬環境以隔離項目依賴。 3)使用Anaconda管理數據科學項目中的Python版本。 4)保留系統Python用於系統級任務。通過這些工具和策略,你可以有效地管理不同版本的Python,確保項目順利運行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基於基於duetoc的iMplation,2)2)他們的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函數函數函數函數構成和穩定性構成和穩定性的操作,製造


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具