To my mind there are too many differences between running code as a script and running it in the REPL.  This would, presumably, add another one: the initial line would be executed without waiting to see if there is a dot continuation line.  And it just feels wrong to have a complete syntactically valid line of code ... not be a complete line of code.  You can always add outer brackets, as in other situations where lines of code become over-long:

 y = (x.rstrip("\n")
       .split(":")[0]
       .lower())

-1
Rob Cliffe

On 12/03/2021 15:32, Matt Williams 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 -- 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/LWB3U5BTGC4CT26U4AB676SKGED3ZOEX/
Code of Conduct: http://python.org/psf/codeofconduct/

_______________________________________________
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/GVVLTS2EYLB7WKQ625RUOXSQHR3SOQ6E/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to