I'm looking for one liner which will remove all the blank lines from a file in python. python equivalent for --> grep -v '^$' file_name > file_name
grep -v '^$' file_name > file_name
lines = [i for i in open(file_path) if i[:-1]]
If writing to another file is a requirement, you can use file_object.writelines(lines) with opening file for writing.
file_object.writelines(lines)
1.4m articles
1.4m replys
5 comments
57.0k users