我正在尝试创建一个 for 循环,将列表中的每一行打印到文件中,但是我收到了这个错误。有什么帮助吗?谢谢
def write_file(filename, rabbitlist, foxlist, finallist, averagefox, averagerabbit):
# Opens File for Data Input
outfile = open(str(filename) + ".csv", 'w')
# Writes Data to Newly Created File
finalresult = "\n".join(", ".join(map(str, l)) for l in finallist)
outfile.write(str("Day, Foxes, Rabbits, , Average Foxes, Average Rabbits\n"))
lastline = [0, foxlist[0], rabbitlist[0], " ", averagefox, averagerabbit]
for item in lastline:
outfile.write(" %s", item)
outfile.close()
我得到的错误是:Python: TypeError: takes exactly 1 argument (2 given)