def wrap_paragraphs(text, ncols=80):
 paragraph_re = re.compile('\\n(\\s*\\n)+', re.MULTILINE)
 text = dedent(text).strip()
 paragraphs = paragraph_re.split(text)[::2]
 out_ps = []
 indent_re = re.compile('\\n\\s+', re.MULTILINE)
 for p in paragraphs:
  if (indent_re.search(p) is None):
   p = textwrap.fill(p, ncols)
  out_ps.append(p)
 return out_ps

def wrap_paragraphs ( text , ncols = 80 ) : paragraph_re = re . compile ( '\\n(\\s*\\n)+' , re . MULTILINE ) text = dedent ( text ) . strip ( ) paragraphs = paragraph_re . split ( text ) [ : : 2 ] out_ps = [ ] indent_re = re . compile ( '\\n\\s+' , re . MULTILINE ) for p in paragraphs : if ( indent_re . search ( p ) is None ) : p = textwrap . fill ( p , ncols ) out_ps . append ( p ) return out_ps
wrap multiple paragraphs to fit a specified width .