import os
path = r'C:\Users\shinelon\Desktop\新建文件夹' # 替换你的文件夹
path_result = path+"\结果"
listdir = os.listdir(path)
try:
os.mkdir(path_result)
except FileExistsError:
pass
except:
print('已经改写,若重改请删除结果文件夹')
for f_name in listdir:
path_filename = path+"\\"+f_name
print(path_filename)
with open(path_filename) as txt:
for i in txt.readlines():
a = i.split(',')
b = a[2].split('.')
c = str(int(b[0])+1) +'.'+ b[1]
d = a[0] + ',' + a[1] + ',' + c
with open(path_result+'\\'+f_name,'a') as txt_result:
txt_result.write(d)
os.startfile(path_result)
f=open(path,'w') 这里的“path”代表你要将文件放在哪里的路径例如“C://Users/a.txt”f.write(String) 这里的“String”代表你要写进文件的数据
#-*- coding:utf-8 -*-
import re
import os
filepath='E:\\data11-20\\0.025'
#filepath=os.getcwd()
lst=[]
for i in range(3,100):
filename='plane1-conv{:03d}.out'.format(i)
fullname=(os.sep).join([filepath,filename])
with open(fullname) as f:
s=f.read()().strip()
lst1=[re.split(r'\s+',si.strip())[-1] for si in s.split('\n')]
lst.append(lst1)
#lst是一个二维数组,每个文件的最后一列作为一个一维数组存在里面
#然后找出最长列的长度lmax,其他比它短的数据列,用lmax-len(i)组空格补到和它一样长
#每组空格的数目等于数据列的第一个数据的长度
lmax=max([len(i) for i in lst])
ws=[i+[' '*len(i[0])]*(lmax-len(i)) for i in lst]
with open('E:\\hehe.txt','w') as wf:
wf.write('\n'.join([' '.join(i) for i in ws]))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)