Re: regex to remove lines made of only whitespace

2010-08-11 Thread Chris Withers
Steven D'Aprano wrote: def strip_blank_lines(lines): for line in lines: if not line.isspace(): yield line text = ''.join(strip_blank_lines(lines.split('\n'))) The final version I have is: def strip_blank_lines(text): result = [] for line in text.split('\n'):

RE: regex to remove lines made of only whitespace

2010-08-11 Thread Andreas Tawn
> On 08/11/10 06:21, Andreas Tawn wrote: > >> I'm looking for a regex (or other solution, as long as it's quick!) > >> that could be used to strip out lines made up entirely of > whitespace. > >> > >> eg: > >> > >> 'x\n \t \n\ny' -> 'x\ny' > > > > for line in lines: > > if not line.strip():

Re: regex to remove lines made of only whitespace

2010-08-11 Thread Steven D'Aprano
On Wed, 11 Aug 2010 12:13:29 +0100, Chris Withers wrote: > Hi All, > > I'm looking for a regex (or other solution, as long as it's quick!) that > could be used to strip out lines made up entirely of whitespace. def strip_blank_lines(lines): for line in lines: if not line.isspace():

Re: regex to remove lines made of only whitespace

2010-08-11 Thread Tim Chase
On 08/11/10 06:21, Andreas Tawn wrote: I'm looking for a regex (or other solution, as long as it's quick!) that could be used to strip out lines made up entirely of whitespace. eg: 'x\n \t \n\ny' -> 'x\ny' for line in lines: if not line.strip(): continue doStuff(line) No

RE: regex to remove lines made of only whitespace

2010-08-11 Thread Andreas Tawn
> Hi All, > > I'm looking for a regex (or other solution, as long as it's quick!) > that > could be used to strip out lines made up entirely of whitespace. > > eg: > > 'x\n \t \n\ny' -> 'x\ny' > > Does anyone have one handy? > > cheers, > > Chris for line in lines: if not line.strip():

regex to remove lines made of only whitespace

2010-08-11 Thread Chris Withers
Hi All, I'm looking for a regex (or other solution, as long as it's quick!) that could be used to strip out lines made up entirely of whitespace. eg: 'x\n \t \n\ny' -> 'x\ny' Does anyone have one handy? cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting