面试题答案
一键面试try:
with open('your_file.txt', 'r', encoding='utf-8') as file:
for line in file:
print(line.strip())
except FileNotFoundError:
print("文件不存在")
except Exception as e:
print(f"读取文件时出现其他异常: {e}")
try:
with open('your_file.txt', 'r', encoding='utf-8') as file:
for line in file:
print(line.strip())
except FileNotFoundError:
print("文件不存在")
except Exception as e:
print(f"读取文件时出现其他异常: {e}")