面试题答案
一键面试try:
with open('nonexistent_file.txt', 'r') as file:
content = file.read()
except FileNotFoundError:
print("很抱歉,您要打开的文件不存在。")
# 异常处理完毕后继续的其他逻辑
print("程序继续执行其他操作...")
try:
with open('nonexistent_file.txt', 'r') as file:
content = file.read()
except FileNotFoundError:
print("很抱歉,您要打开的文件不存在。")
# 异常处理完毕后继续的其他逻辑
print("程序继续执行其他操作...")