Python异常处理 try-except。
异常处理
"""
异常处理
"""
try:
with open("file/read.txt", encoding = "UTF-8") as file_obj:
lines = file_obj.readlines()
except FileNotFoundError:
# 或者 pass 关键字忽略错误
print("file not found")
else:
# 没有异常抛出时执行
for line in lines:
print(line)