I have written tens of thousands of lines of Pandas code, and I've taught
thousands of people to use Pandas. I've worked with the core developers of
Pandas as well.

This is the first time I've ever seen `\` line continuation used for fluent
programming style rather than just using parentheses as a way of expressing
a logical line.

On Fri, Mar 12, 2021, 10:41 AM Matt Williams <[email protected]> wrote:

> Hi,
>
> It's becoming more popular in Python to have interfaces which are built
> around method chaining as a way of applying operations to data. For example
> in pandas is moving more towards a default model where methods do not
> change the object in-place but instead return an altered version (or at
> least an altered view) of it.
>
> The major downside to method chaining is that it ends up creating long
> lines of code which can become hard to read. The two main solutions to this
> are 1) break down the chain and give the steps their own variable names and
> 2) split it over multiple lines using `\` as a line continuation.
>
> e.g.:
>
>   y = x.rstrip("\n").split(":")[0].lower()
>
> would become
>
>   y = x.rstrip("\n") \
>        .split(":")[0] \
>        .lower()
>
> I find the continuation character visually distracting, easy to forget and
> does not allow for line-by-line commenting (causing `SyntaxError:
> unexpected character after line continuation character`):
>
>   y = x.rstrip("\n") \
>        .split(":")[0] \  # grab the key name
>        .lower()
>
> My idea is to alter the syntax of Python to allow doing:
>
>   y = x.rstrip("\n")
>        .split(":")[0]
>        .lower()
>
> i.e., not requiring an explicit line continuation character in the case
> where the next line starts with a period.
>
> I've had a search through the archives and I couldn't see this discussion
> before. Feel free to point me to it if I've missed anything.
>
> Cheers,
> Matt
> _______________________________________________
> Python-ideas mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/LWB3U5BTGC4CT26U4AB676SKGED3ZOEX/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/ZVRFLX5QK4C65KWE3U43HHCZSOXK23NJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to