創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!
這篇文章主要介紹python3.7進(jìn)行調(diào)試的方法,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!
python3.7調(diào)試的方法:首先將光標(biāo)移動到需要設(shè)置斷點(diǎn)調(diào)試的行;然后雙擊代碼編輯處左側(cè)邊緣,出現(xiàn)紅色小圓點(diǎn);再點(diǎn)擊主窗口右上方的綠色蟲子圖標(biāo),在窗口左下方即可看到調(diào)試控制臺,點(diǎn)擊控制臺上方的箭頭即可分步調(diào)試。
PyCharm IDE 窗口布局
PyCharm 調(diào)試代碼實(shí)例(這里我以自己的代碼為例)
__author__ = 'lxm' #!/usr/bin/python import thread import time # Define a function for the thread def print_time( threadName, delay): count = 0 while count < 5: count += 1 print "%s: %s" % ( threadName, time.ctime(time.time()) ) def check_sum(threadName,valueA,valueB): print "to calculate the sum of two number her" result=sum(valueA,valueB) print "the result is" ,result; def sum(valueA,valueB): if valueA >0 and valueB>0: return valueA+valueB def readFile(threadName, filename): file = open(filename) for line in file.xreadlines(): print line try: thread.start_new_thread( print_time, ("Thread-1", 2, ) ) thread.start_new_thread( check_sum, ("Thread-2", 4,5, ) ) thread.start_new_thread( readFile, ("Thread-3","test.txt",)) except: print "Error: unable to start thread" while 1: # print "end" pass
在調(diào)試之前通常需要設(shè)置斷點(diǎn),斷點(diǎn)可以設(shè)置在循環(huán)或者條件判斷的表達(dá)式處或者程序的關(guān)鍵點(diǎn)。設(shè)置斷點(diǎn)的方法非常簡單:在代碼編輯框中將光標(biāo)移動到需要設(shè)置斷點(diǎn)的行,然后直接按 Ctrl+F8 或者選擇菜單"Run"->"Toggle Line Break Point",更為直接的方法是雙擊代碼編輯處左側(cè)邊緣,可以看到出現(xiàn)紅色的小圓點(diǎn)。當(dāng)調(diào)試開始的時候,當(dāng)前正在執(zhí)行的代碼會直接顯示為藍(lán)色。下圖中設(shè)置了三個斷點(diǎn),藍(lán)色高亮顯示的為正在執(zhí)行的代碼。
斷點(diǎn)設(shè)置
表達(dá)式求值:在調(diào)試過程中有的時候需要追蹤一些表達(dá)式的值來發(fā)現(xiàn)程序中的問題,Pycharm 支持表達(dá)式求值,可以通過選中該表達(dá)式,然后選擇“Run”->”Evaluate Expression”,在出現(xiàn)的窗口中直接選擇 Evaluate 便可以查看。
Pycharm同時提供了 Variables 和 Watches 窗口,其中調(diào)試步驟中所涉及的具體變量的值可以直接在 variable 一欄中查看。
變量查看
如果要動態(tài)的監(jiān)測某個變量可以直接選中該變量并選擇菜單”Run”->”Add Watch”添加到 watches 欄中。當(dāng)調(diào)試進(jìn)行到該變量所在的語句時,在該窗口中可以直接看到該變量的具體值。
以上是python3.7進(jìn)行調(diào)試的方法的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!
標(biāo)題名稱:python3.7進(jìn)行調(diào)試的方法-創(chuàng)新互聯(lián)
轉(zhuǎn)載來源:http://m.newbst.com/article46/dcepeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、網(wǎng)站改版、服務(wù)器托管、定制開發(fā)、自適應(yīng)網(wǎng)站、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)