赞
踩
try:
检测范围
exception[as reason]:
出现异常(Exception)后的处理代码
一个try 语句搭配多个Exception ,对异常进行分别处理
try:
检测范围
exception OSError as reason:
处理异常
exception TypeError as reason:
处理异常
try:
file= open("a.txt", "w+")
file.read()
temp= 1 / 0
except (IOError,ZeroDivisionError) as ercode:
print("错误,错误代码为:" + str(ercode))
else:
print("写入成功")
file.close
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。