文件读写与 with 语句 — 计算机选择题
题目
已有 UTF-8 文件“输入.txt”,内容为两行“春风
秋雨
”;已有文件“输出.txt”,内容为“旧记录
”。执行以下代码后,关于“输出.txt”的内容及文件关闭情况,哪项正确?
with open('输入.txt', 'r', encoding='utf-8') as src:
with open('输出.txt', 'w', encoding='utf-8') as dst:
for line in src:
dst.write(line)
A. 内容为“旧记录
春风
秋雨
”,两个文件均自动关闭
B. 内容为“春风
秋雨
”,两个文件均自动关闭
C. 内容为“春风
秋雨
”,只有“输入.txt”自动关闭
D. 内容为“旧记录
”,两个文件均自动关闭