test.txt
gdpu
is
my
love
文件名为: test.txt
t.txt
FileNotFoundError
文件名为: t.txt
你题目的解答代码如下:
def f(fn):
try:
with open(fn, 'r', encoding='utf-8') as fileObj:
print(fileObj.read())
except Exception as e:
print(type(e).__name__)
print('文件名为:',fn)
fn = input()
f(fn)
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!