[Python-Dev] Re: Multiline string constants, include in the standard library?
Ville Vainio
ville.vainio@swisslog.com
Mon, 29 Jul 2002 11:10:58 +0300
Fran=E7ois Pinard wrote:
>>> >>> def stripIndent( s ):
>>> ... indent =3D len(s) - len(s.lstrip())
>>> ... sLines =3D s.split('\n')
>>> ... resultLines =3D [ line[indent:] for line in sLines ]
>>> ... return ''.join( resultLines )
>>> =20
>>>
>
>
> =20
>
>>Something like this should really be available somewhere in the standar=
d
>>library (string module [yeah, predeprecation, I know], string
>> =20
>>
>In fact, I like my doc-strings and other triple-quoted strings flushed l=
eft.
>So, I can see them in the code exactly as they will appear on the screen.
>
Enabling one to strip the indentation wouldn't hurt this practice of=20
yours one bit (nobody forces you to use it). To my eyes left-flushing=20
the blocks disrupts the natural "flow" of the code, and breaks the=20
intuitive block structure of the program.
>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 wort=
h.
>
Could you axplain what you mean by artificially constricted? Of course=20
only the amount of space in the left margin would be removed,=20
indentation would work exactly the same.
Which one looks better:
++++++++++++++++++++++++
def usage():
if 1:
print """\
You should have done this
and that
""".stripindent()
+++++++++++++++++++++++++
def usage():
if 1:
print """\
You should have done this
and that
"""
++++++++++++++++++++++++++
When you are scanning code, the non-stripindent version of the 3-quoted=20
string jumps at your face as a "top-level" construct, even if it is only=20
associated with the usage() function.
>My opinion is that it is nice this way. Don't touch the thing! :-)
>
Again, the change would not influence your code or practices one bit.
-- Ville