def pretty_message(string, *params):
 output = textwrap.dedent(string)
 if (output.find(u'\n') != (-1)):
  output = re.sub(u'(?<=\\S)\n(?=[^ \n DCTB \\d\\*\\-=])', u' ', output)
 if params:
  output = (output % params)
 output = output.strip()
 return output

def pretty_message ( string , * params ) : output = textwrap . dedent ( string ) if ( output . find ( u'\n' ) != ( - 1 ) ) : output = re . sub ( u'(?<=\\S)\n(?=[^ \n DCTB \\d\\*\\-=])' , u' ' , output ) if params : output = ( output % params ) output = output . strip ( ) return output
takes a multi-line string and does the following: - dedents - converts newlines with text before and after into a single line - strips leading and trailing whitespace .