Indented multi-line strings
Peter J. Holzer
hjp-python at hjp.at
Thu May 31 17:16:10 EDT 2018
On 2018-05-31 16:44:10 +0100, MRAB wrote:
> I was also thinking that it could take the indentation from the first line,
> but that if you wanted the first line to have a larger indent than the
> remaining lines, you could replace the first space that you want to keep
> with a non-whitespace character and then pass that character to the method.
>
> For example:
>
> Test = """\
> _ Hello, this is a
> Multiline indented
> String
> """.outdent(padding='_')
>
> Outdent so that the first line is flush to the margin:
>
> _ Hello, this is a
> Multiline indented
> String
>
> The padding argument tells it to replace the initial '_':
>
> Hello, this is a
> Multiline indented
> String
I would prefer to remove the padding, like this:
Test = """
| Hello, this is a
| Multiline indented
|String
""".outdent(padding='|')
Or write it like this?
Test = """| Hello, this is a
| Multiline indented
|String
""".outdent(padding='|')
Hmm, the sign of Zorro! :-)
I'm starting to like outdent(), but that may be my TIMTOWTDIism
speaking.
hp
--
_ | Peter J. Holzer | we build much bigger, better disasters now
|_|_) | | because we have much more sophisticated
| | | hjp at hjp.at | management tools.
__/ | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20180531/5f2e64b9/attachment.sig>
More information about the Python-list
mailing list