python脚本:删除行内所有空格

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#/usr/bin/env python

'''
该脚本用于删除文件每行中存在的空格;尤其是从kindle中复制出来的的笔记带有很多空格符,手动去除很麻烦,所以写了这个脚本
auther: dreampython
date: 2018-10-3
'''
import re
def replace():
pattern = r'\s+'
with open('notes_read_Country_Driving.md',encoding='utf8') as f:
lines = f.readlines()
for line in lines:
print(re.sub(pattern,'',line))

def main():
replace()

if __name__ == '__main__':
main()