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)
2.1m questions
2.1m answers
60 comments
57.0k users