Indented multi-line strings (was: "Data blocks" syntax specification draft)
Chris Angelico
rosuav at gmail.com
Wed May 23 13:42:04 EDT 2018
On Thu, May 24, 2018 at 3:08 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> I don't know if 'i' would be the right prefix character for this, but
> it's unused and is short for 'indented':
>
> b = i'''
> Here is a multi-line string
> with indentation, which is
> determined from the second
> line.'''
Since this doesn't change the way the string is parsed, it doesn't
actually NEED to be a prefix letter. I'd like to see this instead:
b = '''
Here is a multi-line string
with indentation, which is
determined from the second
line.'''.dedent()
Implemented as a string method, it would be completely syntactically
forwards and backwards compatible, and could be easily documented
(s.dedent() <=> textwrap.dedent(s)). And methods on literals are open
to being optimized, as there's no way to mess with imports or
anything.
ChrisA
More information about the Python-list
mailing list