def rewrap ( s , width = COLS ) : s = ' ' . join ( [ l . strip ( ) for l in s . strip ( ) . split ( '\n' ) ] ) return '\n' . join ( textwrap . wrap ( s , width ) )
fixed width text in python
Join all lines from input string and wrap it at specified width
def rewrap(s, width=COLS):
    """ Join all lines from input string and wrap it at specified width """
    s = ' '.join([l.strip() for l in s.strip().split('\n')])
    return '\n'.join(textwrap.wrap(s, width))