[Python-Dev] Re: Multiline string constants, include in the standard library?

François Pinard pinard@iro.umontreal.ca
26 Jul 2002 11:05:39 -0400


[Ville Vainio]

> >     where stripIndent() has been defined as:
> >
> >     >>> def stripIndent( s ):
> >     ...     indent = len(s) - len(s.lstrip())
> >     ...     sLines = s.split('\n')
> >     ...     resultLines = [ line[indent:] for line in sLines ]
> >     ...     return ''.join( resultLines )


> Something like this should really be available somewhere in the standard
> library (string module [yeah, predeprecation, I know], string
> method). Everybody needs this kind of functionality, and probably more often
> than many of the other string methods (title, swapcase come to mind).

Strange.  I did a lot of Python programming, and never needed this.

In fact, I like my doc-strings and other triple-quoted strings flushed left.
So, I can see them in the code exactly as they will appear on the screen.
If I used artificial margins in Python so my doc-strings appeared to be
indented more than the surrounding, and wrote my code this way, it would
appear artificially constricted on the left once printed.  It's not worth.

For me, best is to use """\ always while the opening triple-quote,
and write flushed left until the closing """.  As most long strings end
with a new line, the closing """ is usually flushed left just as well.
My opinion is that it is nice this way.  Don't touch the thing! :-)

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard