Here's how we normalize whitespace in multiline blocks of text. Perhaps
you can adapt this routine to your needs? Watch for line wrap.

# clean up duplicate whitespace, leading/trailing whitespace, triple
CRLF's
def fixwhitespace( text ):
        output = []
        lastLine = ''
        
        # split text into list of individual lines
        lines = text.strip().splitlines()
        for line in lines:
                # remove leading, trailing, and duplicate whitespace within a 
line
                line = ' '.join( line.split( None ) )
                
                # ignore multiple blank lines
                if not line and not lastLine:
                        pass
                else:
                        output.append( line )
                lastLine = line
        
        return '\n'.join( output )

Regards,
Malcolm
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to