python write和writelines的区别
file.write(str)的参数是一个字符串,就是你要写入文件的内容.
file.writelines(sequence)的参数是序列,比如列表,它会迭代帮你写入文件。
下面两种方式写入文件的效果是一样的
with open(fname,"w",encoding = "utf-8") as f:
f.writelines(["%s%s"%(x,ls) for x in all])
with open(fname,"w",encoding = "utf-8") as f:
for x in all:
f.write("%s%s" % (x, ls))