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

Leave a Comment