Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why not python implicit line continuation on period?

Tags:

python

Is there any reason Python does not allow implicit line continuations after (or before) periods? That is

data.where(lambda d: e.name == 'Obama').
    count()


data.where(lambda d: e.name == 'Obama')
    .count()

Does this conflict with some feature of Python? With the rise of method chaining APIs this seems like a nice feature.

like image 382
Tristan Avatar asked Apr 08 '26 02:04

Tristan


2 Answers

Both of those situations can lead to valid, complete constructs, so continuing on them would complicate the parser.

print 3.
  1415926

print 'Hello, world'
  .lower()
like image 99
Ignacio Vazquez-Abrams Avatar answered Apr 09 '26 15:04

Ignacio Vazquez-Abrams


Python allow line continuations within parentheticals (), so you might try:

(data.where(lambda d: e.name == 'Obama').
    count())

I know that's not answering your question ("why?"), but maybe it's helpful.

like image 43
dkamins Avatar answered Apr 09 '26 16:04

dkamins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!