新聞中心
python3.7調(diào)試的方法:首先將光標(biāo)移動到需要設(shè)置斷點調(diào)試的行;然后雙擊代碼編輯處左側(cè)邊緣,出現(xiàn)紅色小圓點;再點擊主窗口右上方的綠色蟲子圖標(biāo),在窗口左下方即可看到調(diào)試控制臺,點擊控制臺上方的箭頭即可分步調(diào)試。
目前創(chuàng)新互聯(lián)建站已為上1000+的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機、網(wǎng)站托管、服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計、臨洮網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
PyCharm IDE 窗口布局
PyCharm 調(diào)試代碼實例(這里我以自己的代碼為例)
__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è)置斷點,斷點可以設(shè)置在循環(huán)或者條件判斷的表達式處或者程序的關(guān)鍵點。設(shè)置斷點的方法非常簡單:在代碼編輯框中將光標(biāo)移動到需要設(shè)置斷點的行,然后直接按 Ctrl+F8 或者選擇菜單"Run"->"Toggle Line Break Point",更為直接的方法是雙擊代碼編輯處左側(cè)邊緣,可以看到出現(xiàn)紅色的小圓點。當(dāng)調(diào)試開始的時候,當(dāng)前正在執(zhí)行的代碼會直接顯示為藍色。下圖中設(shè)置了三個斷點,藍色高亮顯示的為正在執(zhí)行的代碼。
斷點設(shè)置
表達式求值:在調(diào)試過程中有的時候需要追蹤一些表達式的值來發(fā)現(xiàn)程序中的問題,Pycharm 支持表達式求值,可以通過選中該表達式,然后選擇“Run”->”Evaluate Expression”,在出現(xiàn)的窗口中直接選擇 Evaluate 便可以查看。
Pycharm同時提供了 Variables 和 Watches 窗口,其中調(diào)試步驟中所涉及的具體變量的值可以直接在 variable 一欄中查看。
變量查看
如果要動態(tài)的監(jiān)測某個變量可以直接選中該變量并選擇菜單”Run”->”Add Watch”添加到 watches 欄中。當(dāng)調(diào)試進行到該變量所在的語句時,在該窗口中可以直接看到該變量的具體值。
推薦課程:Python 基礎(chǔ)入門教程
當(dāng)前文章:創(chuàng)新互聯(lián)Python教程:python3.7如何調(diào)試
本文來源:http://fisionsoft.com.cn/article/cdcepih.html


咨詢
建站咨詢

