How to remove empty lines with re?

Tim Haynes thaynes at openlinksw.com
Fri Oct 10 09:15:20 CEST 2003


"ted" <tedNOSPAM94107 at yahoo.com> writes:

> f = open("old_site/index.html")
> for line in f:
>     line = re.sub(r'^\s+$|\n', '', line)              # }
>     print line                                        # }


If you will set a variable to an empty string and then print it, you will
get an empty line printed ;)

~Tim
-- 
Product Development Consultant
OpenLink Software
Tel: +44 (0) 20 8681 7701
Web: <http://www.openlinksw.com>
Universal Data Access & Data Integration Technology Providers




More information about the Python-list mailing list