大文件查找与空格替换

with open(file_name) as file:
    do_something()

多余的空格替换
由于需要用到csv文件(Excel的视图功能,所以需要把连着的空白符替换为逗号,这样方便查看)

import re
file_out = open(filename,"w")
#注意换行
file_out.write(re.sub('\s+',',',line).strip() + "\n")
#注意最后file_out.close()
posted @ 2016-09-12 14:53  ply616  阅读(228)  评论(0编辑  收藏  举报