Need cleanup advice for multiline string

Dave Angel davea at
Wed Aug 12 04:54:49 CEST 2009

Robert Dailey wrote:
> Hey guys. Being a C++ programmer, I like to keep variable definitions
> close to the location in which they will be used. This improves
> readability in many ways. However, when I have a multi-line string
> definition at function level scope, things get tricky because of the
> indents. In this case indents are serving two purposes: For syntax and
> actual text output. The tabs for function scope should not be included
> in the contents of the string. Below is the code I am trying to
> improve. Notice how it looks ugly/unreadable because of the way the
> string contents are shifted all the way to the left edge of the
> document. This breaks the flow of scope. Would you guys solve this
> problem by moving failMsg into global scope? Perhaps through some
> other type of syntax?
> Help is appreciated!
> def RunCommand( commandList ):
>    commandString =
>    print( 'Running Command:',  )
>    cmd = subprocess.Popen( commandList )
>    returnCode = cmd.wait()
>    if returnCode:
>       failMsg = '''\
> *************************************************
> The following command returned exit code [{:#x}].
> This represents failure of some form. Please review
> the command output for more details on the issue.
> ------------
> {}
> *************************************************
> '''
>       commandString = ' '.join( commandList )
>       raise CommandFailure( failMsg.format( returnCode,
> commandString ) )
No, don't put it in global scope.  Put it externally, so it can be 
readily localized for international markets.


More information about the Python-list mailing list