[Python-ideas] New str whitespace cleaning method?
Greg Ewing
greg.ewing at canterbury.ac.nz
Sat May 25 03:49:57 CEST 2013
Wolfgang Maier wrote:
> personally, I'd
> prefer that method to remove a fixed specified number of spaces from the
> beginning of each line,
>
> if format_output:
> print ("""\
> 1)
> Indent *only* the first line
> of a paragraph,
> 2)
> Have pretty-formatted numbered
> lists
> independent of the code indentation level.""".ltrim(16))
This makes it abundantly unclear how much is being
stripped without a close study of the code and then
carefully counting whitespace characters, being sure
to count tabs as one character.
Also, if you change the indentation level of the code, you
have to change the embedded numeric literal to match or
it breaks.
I'd prefer some kind of dedented-string-literal syntax
that explicitly marks how much to trim from each line,
e.g.
print(d"""This text has no
| whitespace at the beginning of any
|line except the second one,
|which begins with 3 spaces.""")
This would be clear to read and easy to edit.
--
Greg
More information about the Python-ideas
mailing list