python: how to check if a line is an empty line
If you want to ignore lines with only whitespace:
if line.strip():
... do something
The empty string is a False value.
Or if you really want only empty lines:
if line in ['\n', '\r\n']:
... do something
I use the following code to test the empty line with or without white spaces.
if len(line.strip()) == 0 :
# do something with empty line