python 把文件内容分成三列
发布网友
发布时间:2022-04-23 04:59
我来回答
共1个回答
热心网友
时间:2023-09-29 08:33
#!/usr/bin/env python
with open('file.txt') as f:
d=f.readlines()
with open('file.txt','w') as f:
for i in range(len(d)):
if (i+1)%3!=0:
f.write('%s ' %d[i].strip())
else:
f.write(d[i])