把txt文本框的坐标信息合到一个文本里面
f1=open('list.txt','r') #每个坐标位置信息txt路径
f2=open('temp.txt','w') #把所有的坐标信息合到一起
for line in f1:
name=line.split('\n')
f=open(name[0],'r')
a=f.read()
f2.write(a+'\n')
f.close()
f1.close()
f2.close()
#把temp.txt文本里面的空行去掉
f1=open('temp.txt','r')
f2=open('new.txt','w')
for line in f1:
if line == '\n':
line = line.strip("\n")
f2.write(line)
f1.close()
f2.close()
# -*- coding:utf-8 -*-
#os模块中包含很多操作文件和目录的函数
import os
meragefiledir = os.getcwd()+'\\labels'
#获取当前文件夹中的文件名称列表
filenames=os.listdir(meragefiledir)
#打开当前目录下的result.txt文件,如果没有则创建
file=open('result11.txt','w')
for filename in filenames:
filepath=meragefiledir+'\\'
filepath=filepath+filename
for line in open(filepath):
line=line.strip()
if len(line)!=0:
file.writelines(line)
file.write('\n')
#关闭文件
file.close() #此代码会把空行生成在result11.txt里面
#此代码须在文本路径下运行
#!/usr/bin/python
import sys
import importlib
importlib.reload(sys)
import os
import os.path
import time
time1=time.time()
def MergeTxt(filepath,outfile):
k = open(filepath+outfile, 'a+')
for parent, dirnames, filenames in os.walk(filepath):
for filepath in filenames:
txtPath = os.path.join(parent, filepath)
#name = txtPath.split('\n')
f = open(txtPath,encoding='UTF-8')
k.write(f.read())
k.close()
print("finished")
if __name__ == '__main__':
filepath="F:/zxwPythoncode/labels/"
outfile="result111.txt"
MergeTxt(filepath,outfile)
time2 = time.time()
print(u'总共耗时:' + str(time2 - time1) + 's')