file_in = "file_in.txt"
file_out = "file_out.txt"
data = ""
# read the first 3 lines of file_in.txt
with open(file_in, 'r') as f:
for i in range(3):
data += f.readline()
# write to file_out.txt
with open(file_out, 'w') as f:
f.write(data)
# read the content of file_out.txt
with open(file_out, 'r') as f:
content = f.read()
print(content)
1条答案
按热度按时间kjthegm61#