How about:
text = os.linesep.join([s for s in text.splitlines() if s])
where text
is the string with the possible extraneous lines?
How about:
text = os.linesep.join([s for s in text.splitlines() if s])
where text
is the string with the possible extraneous lines?