Message342373
A Python pattern in code is to keep everything indented to look pretty while, yet when the triple quoted multiline string in question needs to not have leading whitespace, calling textwrap.dedent("""long multiline constant""") is a common pattern.
rather than doing this computation at runtime, this is something that'd make sense to do at compilation time. A natural suggestion for this would be a new letter prefix for multiline string literals that triggers this.
Probably not worth "wasting" a letter on this, so I'll understand if we reject the idea, but it'd be nice to have rather than importing textwrap and calling it all over the place just for this purpose.
There are many workarounds but an actual syntax would enable writing code that looked like this:
```python
class Castle:
def __init__(self, name, lyrics=None):
if not lyrics:
lyrics = df"""\
We're knights of the round table
We dance whene'er we're able
We do routines and scenes
With footwork impeccable.
We dine well here in {name}
We eat ham and jam and spam a lot.
"""
self._name = name
self._lyrics = lyrics
```
Without generating a larger temporary always in memory string literal in the code object that gets converted at runtime to the desired dedented form via a textwrap.dedent() call. I chose "d" as the the letter to mean dedent. I don't have a strong preference if we ever do make this a feature. |
|
Date |
User |
Action |
Args |
2019-05-13 18:40:31 | gregory.p.smith | set | recipients:
+ gregory.p.smith |
2019-05-13 18:40:31 | gregory.p.smith | set | messageid: <1557772831.22.0.440689390024.issue36906@roundup.psfhosted.org> |
2019-05-13 18:40:31 | gregory.p.smith | link | issue36906 messages |
2019-05-13 18:40:30 | gregory.p.smith | create | |
|