直接跳轉到內容

Python 從入門到精通/使用 Idle 進行除錯

來自華夏公益教科書,開放世界開放書籍

IDLE 不僅僅是編輯器和命令 shell。IDLE 具有內建的高階偵錯程式,具備任何互動項都應具備的大多數功能。

問題是,任何偵錯程式中最重要的功能是 trace、斷點和監視功能。此外,優秀的偵錯程式應該允許您檢查變數和物件。

我們來看一下 IDLE 是否提供了所有這些功能。

以下是可複製貼上到 IDLE 編輯器中用於此練習的程式碼。

import re
#
def isEmail (text):
    if (len(text) == 0):
        return False
    parts = text.split("@")
    if (len(parts) != 2 ):
        return False
    if (len(parts[0]) > 64):
        return False
    if (len(parts[1]) > 255):
        return False
    if ( re.search( "gov$", parts[1] ) ):
        return False 
    address = "(^[\\w!#$%&'*+/=?^`{|}~-]+(\\.[\\w!#$%&'*+/=?^`{|}~-]+)*$)"
    quotedText = "(^\"(([^\\\\\"])|(\\\\[\\\\\"]))+\"$)"
    localPart = address + "|" + quotedText
    if ( re.match(localPart, parts[0]) == None ):
        return False;
    hostnames = "(([a-zA-Z0-9]\\.)|([a-zA-Z0-9][-a-zA-Z0-9]{0,62}[a-zA-Z0-9]\\.))+"
    tld = "[a-zA-Z0-9]{2,6}"
    domainPart = "^" + hostnames + tld + "$";
    if ( re.match(domainPart, parts[1]) == None ):
        return False
    return True
#
text = "guido@python.com"
if (isEmail(text) ):
    print text + " is a valid email address"
else:
    print text + " is not a valid email address"
print "done"
華夏公益教科書