473,289 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

line continuation for lines ending in "and" or "or"

I've always appreciated Python's lack of requirement for a semi-colon
at the end of each line. I also appreciate its rules for automatic
line continuation. If a statement ends with a "+", for example, Python
recognizes that the statement obviously must continue.

I've noticed, however, that the same rule does not apply when a line
ends with "and," "or," or "not." Yes, it's a minor point, but
shouldn't the same rule apply?

Seems like it would be easy to add.
Jun 27 '08 #1
6 1961
On Jun 4, 10:09*pm, "Russ P." <Russ.Paie...@gmail.comwrote:
I've always appreciated Python's lack of requirement for a semi-colon
at the end of each line. I also appreciate its rules for automatic
line continuation. If a statement ends with a "+", for example, Python
recognizes that the statement obviously must continue.

I've noticed, however, that the same rule does not apply when a line
ends with "and," "or," or "not." Yes, it's a minor point, but
shouldn't the same rule apply?

Seems like it would be easy to add.
Huh? This doesn't work either:
>>x = 2 +
File "<stdin>", line 1
x = 2 +
^
SyntaxError: invalid syntax

Implicit line continuation only happens if you have an unmatched '('.
>>x = (2 +
... 2
... )
>>x
4
Jun 27 '08 #2
On Jun 4, 9:01 pm, Dan Bishop <danb...@yahoo.comwrote:
On Jun 4, 10:09 pm, "Russ P." <Russ.Paie...@gmail.comwrote:
I've always appreciated Python's lack of requirement for a semi-colon
at the end of each line. I also appreciate its rules for automatic
line continuation. If a statement ends with a "+", for example, Python
recognizes that the statement obviously must continue.
I've noticed, however, that the same rule does not apply when a line
ends with "and," "or," or "not." Yes, it's a minor point, but
shouldn't the same rule apply?
Seems like it would be easy to add.

Huh? This doesn't work either:
>x = 2 +

File "<stdin>", line 1
x = 2 +
^
SyntaxError: invalid syntax

Implicit line continuation only happens if you have an unmatched '('.
>x = (2 +

... 2
... )>>x

4
Darnit! You're right. I've been reading up on Scala lately, and I
guess I got confused. Well, it wouldn't be a bad idea for Python to do
what I thought it did, *plus* what I said it ought to do.

Scala is a nice language, by the way. Check it out when you get a
chance (http://www.scala-lang.org). I'm thinking about switching over
to it from Python if I can. I just wish it had default arguments and
argument passing by keyword. Now, those are a couple of features that
I really appreciate in Python. Oh, and I wish Scala used "and" and
"or" rather than "&&" and "||". There's another thing Python got right.
Jun 27 '08 #3
Dan Bishop <da*****@yahoo.comwrote:
>On Jun 4, 10:09*pm, "Russ P." <Russ.Paie...@gmail.comwrote:
>I've always appreciated Python's lack of requirement for a semi-colon
at the end of each line. I also appreciate its rules for automatic
line continuation. If a statement ends with a "+", for example, Python
recognizes that the statement obviously must continue.

I've noticed, however, that the same rule does not apply when a line
ends with "and," "or," or "not." Yes, it's a minor point, but
shouldn't the same rule apply?

Seems like it would be easy to add.
...
Implicit line continuation only happens if you have an unmatched '('.
>>>x = (2 +
... 2
... )
>>>x
4
.... or an unmatched [ or an unmatched {.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 27 '08 #4
Dennis Lee Bieber wrote:
On Wed, 4 Jun 2008 21:50:19 -0700 (PDT), "Russ P."
<Ru**********@gmail.comdeclaimed the following in comp.lang.python:
>Darnit! You're right. I've been reading up on Scala lately, and I
guess I got confused. Well, it wouldn't be a bad idea for Python to do
what I thought it did, *plus* what I said it ought to do.
Is it that much of a difficulty to start multiline expresssions with
a (...

That already covers all the conditions you want... Or just using a
line ending of \
(which I find less appealing than the (... )
I suppose this is a matter of "taste". I find using parenthesis to trigger line
continuations undesirable. Lines ending in backslash are explicit and easy to
mentally parse.

-Larry
Jun 27 '08 #5

"Russ P." <Ru**********@gmail.comwrote in message
news:0d**********************************@u6g2000p rc.googlegroups.com...
|. Well, it wouldn't be a bad idea for Python to do
| what I thought it did, *plus* what I said it ought to do.

A line ending in an operator is ambiguous in that it *could* indicate that
the programmer intends to continue on the next line while it also could
indicate that the programmer forgot to finish before hitting return, or
that something got erased but not replaced. Moreover, the second
possibility is actual (it actually happens) and not just theoretical.
Moreover, the next line realistically could 'complete' the incomplete line
'by accident', so that the syntax bug would not get flagged.

In such situations, some might lean toward the plausible guess choice, but
Guido leans in the direction of choosing the bug interpretation. So he
included the '\' mechanism. It is already used in strings to mean "do not
take the next char literally", so having it mean "do not take the following
end-of-line literally" is only a tiny step.

Terry Jan Reedy

Jun 27 '08 #6
On 5 Jun, 22:40, "Terry Reedy" <tjre...@udel.eduwrote:
>
A line ending in an operator is ambiguous in that it *could* indicate that
the programmer intends to continue on the next line while it also could
indicate that the programmer forgot to finish before hitting return, or
that something got erased but not replaced.
Yes, this is an excellent point. For the logical operators, consider
code like the following...

x = obj1.something() and obj2.conditional() and # time for lunch!
obj4.obligatory_something()

Although a trailing "and" or "or" operator might suggest a
continuation of the expression on the next line, one has to consider
whether the next line (or almost any line defining an expression)
should suggest possible membership of an expression on the preceding
line by default for its contents. One could, of course, insist on
indentation to prevent such ambiguity since the second line above
shouldn't be indented further if part of a separate statement. More
work is definitely needed on such a proposal, certainly.

Paul
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: tdi | last post by:
Ok, stupid question for the day. I'm reading the interview with Steve Moret and he says: "Once a lot of scripts started going in we knew there was no way we could back out of using Python." I'm...
1
by: Tomas Christiansen | last post by:
Im trying to make a simple TCP socket "relay" or "proxy", but my skills in Python are not high (yet). The only thing it should do, is to open the connection on behalf of the client, and when the...
7
by: John | last post by:
Thanks. I am writing a C++ code on Linux and Sun OS platform. How to make a procedure sleep or delay? Thanks again. "John Carson" <donaldquixote@datafast.net.au> wrote in message...
3
by: Colleyville Alan | last post by:
I am constructing a SQL command from a function. Some code builds the WHERE clause in a looping structure and passes that as an argument to the SQL-building function. But the results do not...
3
by: Cybertof | last post by:
Hello, I would like to return the good single value from a string value in these cases : Convert.ToSingle("23,30"); Convert.ToSingle("23.30"); // Conversion Error !!! The result should be...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
7
by: GHZ | last post by:
Is this the best way to test every item in a list? def alltrue(f,l): return reduce(bool.__and__,map(f,l)) def onetrue(f,l): return reduce(bool.__or__,map(f,l)) False
3
by: darnnnel | last post by:
I have a a statement as follows: sSQL = "SELECT * FROM QueryCases WHERE Weekday(QueryCases.StartDate) = 1 OR Weekday(QueryCases.StartDate) = 7 ORDER BY QueryCases.StartDate;" I would like to add...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.