python读取文本多行合并一行
# 需要合并的行数
col = 4
# 创建新文件
nf = open("*.txt", "w+")
# 读取初始文件
with open("*.txt", "r") as f:
str = ""
for index, content in enumerate(f):
str += content.strip()
if (index+1) % col == 0:
# print(str)
nf.write(str + "\n")
str = ""
# 记得释放
nf.close()