这是我从以前的代码修改的代码。但是,我收到了这个错误:
TypeError: must be str not list in f1.write(head)
Run Code Online (Sandbox Code Playgroud)
这是产生此错误的代码部分:
from itertools import islice
with open("input.txt") as myfile:
head = list(islice(myfile, 3))
f1.write(head)
f1.close()
Run Code Online (Sandbox Code Playgroud)