新建目录train,并将目录data和data1复制到train下
python test data/,data1/
目录data和data1中包含很多文件,文件中内容都是以空格分隔,将所有文件内容都以空格为分隔符,竖向排列覆盖到train下相应目录中
import sys import os def main(argv): arg=sys.argv[1] print arg data_set_list = [] for data_set_num, data_dir in enumerate(arg.split(","), 1): command="ls -l %s |awk 'NR==2,NR==0 {print $NF}'" % (data_dir) fp=os.popen(command, "r") ret=fp.readlines() for data_name in ret: data_path=data_dir+data_name[0:-1] data_set_list.append(data_path) print("data_set_list:",data_set_list) for data_index, data_set_name in enumerate(data_set_list): f = open(data_set_name,'r') result=f.read() f.close() o=open('train/'+data_set_name,'w') for i in result.split(' '): o.write(i) o.write(' ') o.close if __name__ == "__main__": main(sys.argv[1:])