On 16.06.20 08:40, Paul Sokolovsky wrote:
Hello,
On Tue, 16 Jun 2020 14:37:39 +0900
"Stephen J. Turnbull" <turnbull.stephen...@u.tsukuba.ac.jp> wrote:
Soni L. writes:
> so I propose a \z string escape which lets me write the above as
> shown below:
>
> """switches to toml config format. the old
> 'repos' \z table is preserved as 'repos_old'"""
We already have that, if you don't care about left-alignment:
"""123456789\
... abcdefghi"""
'123456789abcdefghi'
And if you care about left-alignment, but don't care about extra
function call, we have
https://docs.python.org/3/library/textwrap.html#textwrap.dedent
That said, Java (version 13) puts Python to shame with its multi-line
strings, which work "as expected" re: leading indentation out of the
box: https://openjdk.java.net/jeps/355 .
So, I wouldn't "boo, hiss" someone proposing something like:
s = _"""
Just imagine,
this works
like you would expect!
"""
But my response would be my usual - what Python actually needs is
macro/AST preprocessing capability, e.g. support for handling
'<any_char>"""' strings in user-defined manner. But we can ship some
predefined macros, sure. E.g. '_' as a string prefix (like above) would
run a string thru (analog of) textwrap.dedent().
Alternatively the compiler could run such pure functions if their
arguments consist solely of literals (i.e. perform advanced constant
folding).
This means the following
msg = textwrap.dedent('''abc
def
ghi''')
would be converted already at compile-time. Surely it would be
convenient to maintain a list of compatible functions, limited to the
builtins and stdlib.
Another common use case is `str.split`, e.g. `colors = "red green
blue".split()`. This could also be converted at compile-time.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/SYYVOQG6OZT3VG45RCXIRJPMCM5V6SEF/
Code of Conduct: http://python.org/psf/codeofconduct/