1with open("new_file","r") as f:
2 for i in f.readlines():
3 if not i.strip():
4 continue
5 if i:
6 print i,
7
1import os
2
3
4def remove_empty_lines(filename):
5 if not os.path.isfile(filename):
6 print("{} does not exist ".format(filename))
7 return
8 with open(filename) as filehandle:
9 lines = filehandle.readlines()
10
11 with open(filename, 'w') as filehandle:
12 lines = filter(lambda x: x.strip(), lines)
13 filehandle.writelines(lines)