python指定分隔符来分割文件

 

1 import re
2 p = re.compile('AAAAAAAA',re.S)
3 f = open(r"D:\test\oldfile.txt","r").read()
4 paralist = p.split(f)
5 total_num = len(paralist)
6 for paraindex in range(total_num):
7     filewrite=file( r"D:\test\\" + str(paraindex) + ".txt",'w')
8     filewrite.writelines(paralist[paraindex])
9 filewrite.close()

  

 

 

posted @ 2017-03-28 13:20  zhang.ning  阅读(2063)  评论(0编辑  收藏  举报