新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
創(chuàng)新互聯(lián)Python教程:python沒(méi)有報(bào)錯(cuò)提示
python中沒(méi)有報(bào)錯(cuò)提示的代碼示例:

專(zhuān)注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)高密免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上1000家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
def count_words(filename):
try:
with open(filename) as f_obj:
contents=f_obj.read()
except FileNotFoundError:
pass
else:
words=contents.spilt()
num_words=len(words)
print("This file"+filename+'has about'+str(num_words)+'words.')
===========================================================================================
def count_words(filename):
try:
with open(filename) as f_obj:
contents=f_obj.read()
except FileNotFoundError:
message='sorry,the file'+filename+'does not exits'
print(message)
else:
words=contents.spilt()
num_words=len(words)
print("This file"+filename+'has about'+str(num_words)+'words.')原因:
其中使用了 try-except-else 的代碼塊,except是try代碼中錯(cuò)誤時(shí)執(zhí)行,而except中的代碼是pass,也就是在try中代碼錯(cuò)誤時(shí)候直接pass,不給用戶(hù)編寫(xiě)任何的建議和help。
相應(yīng)報(bào)錯(cuò)的代碼也寫(xiě)在了橫線(xiàn)下面。
當(dāng)前文章:創(chuàng)新互聯(lián)Python教程:python沒(méi)有報(bào)錯(cuò)提示
地址分享:http://www.dlmjj.cn/article/coiijdj.html


咨詢(xún)
建站咨詢(xún)
