473,695 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Are line continuations needed?

Hi all,

Python lets you continue a single logical line across more than one
physical line, either by putting a \ at the end or letting it happen
automatically with an incomplete infix operator.

I'm wondering how often is this feature needed? Would there be any
problems if it weren't part of the language?

--
"Sore wa himitsu desu."
To reply by email, remove
the small snack from address.
http://www.esatclear.ie/~rwallace
Jul 18 '05 #1
11 1604
Russell Wallace wrote:
Hi all,

Python lets you continue a single logical line across more than one
physical line, either by putting a \ at the end or letting it happen
automatically with an incomplete infix operator.

I'm wondering how often is this feature needed? Would there be any
problems if it weren't part of the language?


I just needed to use this a few minutes ago, in a class declaration ...

class ParticleDistrib utionBehaviorSe rver \
(Microphysics__ POA.ParticleDis tributionBehavi or):

I had to split the line to fit within 80 columns, and without the '\'
character I get the following error:

=====
$ python scoping_server. py --POA
File "scoping_server .py", line 8
class ParticleDistrib utionBehaviorSe rver
^
SyntaxError: invalid syntax
=====

So the fact that you don't need it in the case of incomplete expressions
eliminates *most* of the need for it, but there are still a few cases
where it is required.

Regards,
Derek.
Jul 18 '05 #2

"Derek Thomson" <de***@hiredgoo ns.org> wrote in message
news:40******@d uster.adelaide. on.net...
Russell Wallace wrote:
Hi all,

Python lets you continue a single logical line across more than one
physical line, either by putting a \ at the end or letting it happen
automatically with an incomplete infix operator.

I'm wondering how often is this feature needed? Would there be any
problems if it weren't part of the language?

I just needed to use this a few minutes ago, in a class declaration ...

class ParticleDistrib utionBehaviorSe rver \
(Microphysics__ POA.ParticleDis tributionBehavi or):

I had to split the line to fit within 80 columns, and without the '\'
character I get the following error:

=====
$ python scoping_server. py --POA
File "scoping_server .py", line 8
class ParticleDistrib utionBehaviorSe rver
^
SyntaxError: invalid syntax
=====

So the fact that you don't need it in the case of incomplete expressions
eliminates *most* of the need for it, but there are still a few cases
where it is required.


Technically, you could have split it at the period, but that
might be even worse in terms of readability.

BTW - why did it have to fit in 80 columns?

John Roth
Regards,
Derek.

Jul 18 '05 #3
Derek Thomson <de***@hiredgoo ns.org> writes:
Russell Wallace wrote:
Hi all,

Python lets you continue a single logical line across more than one
physical line, either by putting a \ at the end or letting it happen
automatically with an incomplete infix operator.

I'm wondering how often is this feature needed? Would there be any
problems if it weren't part of the language?


I just needed to use this a few minutes ago, in a class declaration ...

class ParticleDistrib utionBehaviorSe rver \
(Microphysics__ POA.ParticleDis tributionBehavi or):

I had to split the line to fit within 80 columns, and without the '\'
character I get the following error:

=====
$ python scoping_server. py --POA
File "scoping_server .py", line 8
class ParticleDistrib utionBehaviorSe rver
^
SyntaxError: invalid syntax
=====


This ought to work:

class ParticleDistrib utionBehaviorSe rver(
Microphysics__P OA.ParticleDist ributionBehavio r):

--
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
Hate to interrupt with a spelling flame, but it's "Cheney,"
not "Chaney." It may only be one letter, but it's 998 faces.
- Mike Peterson
Jul 18 '05 #4
John Roth wrote:
Derek Thomson wrote:

class ParticleDistrib utionBehaviorSe rver \
(Microphysics__ POA.ParticleDis tributionBehavi or):

[snip]

So the fact that you don't need it in the case of incomplete expressions
eliminates *most* of the need for it, but there are still a few cases
where it is required.

Technically, you could have split it at the period, but that
might be even worse in terms of readability.


I didn't know that, but yes, it would be ugly.

BTW - why did it have to fit in 80 columns?


Because that's our coding standard. But it wouldn't matter if it was 120
columns, or in fact any number you specify - I can still construct an
example that won't work.

Regards,
Derek.
Jul 18 '05 #5
Mark Jackson wrote:

This ought to work:

class ParticleDistrib utionBehaviorSe rver(
Microphysics__P OA.ParticleDist ributionBehavio r):


In fact it does work - I should have thought of that. I've just checked
in the change to CVS. Thanks!

Now I'll have to think of another case ... I'm sure there was another ...

Regards,
Derek.
Jul 18 '05 #6
Russell Wallace wrote:
Python lets you continue a single logical line across more than one
physical line, either by putting a \ at the end or letting it happen
automatically with an incomplete infix operator.

I'm wondering how often is this feature needed? Would there be any
problems if it weren't part of the language?


Just had this example:

d = { 'key1' : 'A very very long string of several hundred '\
'characters. I could use a multi-line string but '\
'then either left white space would be part of the '\
'string or I would have to align it at column 0 '\
'(ugly). I could embed it into a pair of brackets '\
'but I see no advantage over \\. Finally I could '\
'put this string on a single line (also ugly and hard '\
'to read).'
...
}
Mit freundlichen Gruessen,

Peter Maas

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail pe********@mplu sr.de
-------------------------------------------------------------------
Jul 18 '05 #7
Peter Maas wrote:
Russell Wallace wrote:
Python lets you continue a single logical line across more than one
physical line, either by putting a \ at the end or letting it happen
automatically with an incomplete infix operator.

I'm wondering how often is this feature needed? Would there be any
problems if it weren't part of the language?


Just had this example:

d = { 'key1' : 'A very very long string of several hundred '\
'characters. I could use a multi-line string but '\
'then either left white space would be part of the '\
'string or I would have to align it at column 0 '\
'(ugly). I could embed it into a pair of brackets '\
'but I see no advantage over \\. Finally I could '\
'put this string on a single line (also ugly and hard '\
'to read).'
...
}

d = {1: "Hi Peter, "

.... "what do you "
.... "think of this?"}

Peter

Jul 18 '05 #8
Peter Maas <pe********@mpl usr.de> writes:
Just had this example:

d = { 'key1' : 'A very very long string of several hundred '\
'characters. I could use a multi-line string but '\
'then either left white space would be part of the '\
'string or I would have to align it at column 0 '\
'(ugly). I could embed it into a pair of brackets '\
'but I see no advantage over \\. Finally I could '\
'put this string on a single line (also ugly and hard '\
'to read).'
...
}


Actually that's unnecessary since you are already in a braced
expression from the dictionary constructor. So the lines are
implicitly continuation lines until you close the dictionary, and the
compilers combination of adjacent string constants still works. You
can drop the continuation characters and it'll give the same
dictionary.

I tend to construct parenthetical expressions if I can to avoid the
explicit line continuation character - mostly since I think it looks
nicer, but there are some cases where I prefer the contination.
There's normally an alternative to the continuation, but one that I
don't consider as readable.

For example, one place where I've used line continuations was in
explicit from imports, such as:

from some.package.ex ceptions import ExceptionName, OtherName, \
AnotherName, AndAnotherName

where I find this more readable than repeating the "from <package>
import" portion of the line multiple times.

I also use it to suppress leading newlines in triple quoted strings,
while permitting me to write the entire string at the same indent
level, e.g.:

MSG = """\
blah blah blah

and some more blah blah blah
"""

I'll also use it sometimes for string formatting operations (either
standalone or as part of print) where sometimes I think it looks nicer
than putting the entire expression in parenthesis), e.g.:

some_variable = 'This is a formatting string args %s %s %s' % \
(argument1, argument2, argument3)
-- David
Jul 18 '05 #9
On Wed, 07 Apr 2004 14:05:29 GMT, wa************* *@eircom.net (Russell
Wallace) wrote:
Hi all,

Python lets you continue a single logical line across more than one
physical line, either by putting a \ at the end or letting it happen
automaticall y with an incomplete infix operator.

I'm wondering how often is this feature needed? Would there be any
problems if it weren't part of the language?
I don't have any ready examples, but I do occasionally need it, if
only for readability porpoises, or more often to fit a line to a
certain length limit. If a parenthetical expression will work, and
doesn't look stranger (really can't think of a case), I'll use that.

But problems there'll surely be - with legacy code compatibility.

--
"Sore wa himitsu desu."

Not really it isn't ;-)

--
Christopher
Jul 18 '05 #10

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

Similar topics

1
6560
by: Dennis | last post by:
I started a new thread because i cant reply on the older one. Thank you very much Rick for the usefull reply. But i'v got another question. When drawing the line, you cant see the line untill you release the mouse button. I want to see the line when im drawing!! Im using the following code: Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) x1 = z.X
17
2737
by: Mike Thompson | last post by:
'Seaside' is a Smalltalk framework for what might be called "Modal Web Development" or "Synchronous Web Programming", or even "Continuation Based Web Apps". http://www.beta4.com/seaside2/ Very sexy it looks too. And it seems to be generating a lot of interest - Ruby and Java variants have already sprung up: http://rubyforge.org/projects/borges/
2
2185
by: Jasper Recto | last post by:
I have a statement that I can't seem to use Line Continuations on it: Progress = "V:\PROGRESS\bin\prowin32.exe V:\VANTAGE\db\vantage.db_ -ininame V:\VANTAGE\vantage.ini -pf V:\VANTAGE\db\Vantage.pf -N TCP -H loc-vntg -S epic52 -ld vantage -p v:\" & ReportPath & ReportName & " -rand 2 -q -basekey ini" This is all one line and when I try to use line continuation ( _ ) I keep getting errors.
13
465
by: Kiran Dalvi | last post by:
Hi, Can anybody please suggest me an efficient approach to find out all possible permutations of a String. e.g. My input string = "ABC". My program should give an output like .... ABC, ACB, BAC, BCA, CAB, CBA Thanks, Kiran
2
1253
by: Florian Lindner | last post by:
Hello, http://docs.python.org/lib/module-ConfigParser.html writes: "with continuations in the style of RFC 822; " what is meant with these continuations? Thanks, Florian
6
1398
by: vasudevram | last post by:
Hi, I am Googling and will do more, found some stuff, but interested to get viewpoints of list members on: Continuations in Python. Saw a few URLs which had some info, some of which I understood. But like I said, personal viewpoints are good to have.
13
14668
by: Don | last post by:
Hi, I have an SQL string that I'm trying to code into VBA and it's giving me trouble. I tried to use line continuation and concatenation as best I can to make it work. However, I'm stuck. I know that there are limitations to the length of the string but I can't break it up properly. I'm also thinking that I need to use multiples occurrences of strsql to do so but I'm not sure how. Can someone please tell me how to break this string up?
26
1975
by: gnuist006 | last post by:
Again I am depressed to encounter a fundamentally new concept that I was all along unheard of. Its not even in paul graham's book where i learnt part of Lisp. Its in Marc Feeley's video. Can anyone explain: (1) its origin (2) its syntax and semantics in emacs lisp, common lisp, scheme (3) Is it present in python and java ? (4) Its implementation in assembly. for example in the manner that
7
1163
by: miller.paul.w | last post by:
I've been doing some thinking, and I've halfway convinced myself of the following statement: that threads as implemented by Python (or Java) are exactly equivalent to one-shot continuations in Scheme. Am I right? (I'd have asked in the scheme groups, but I feel like I'm less likely to get flamed to death here... hehe.) If that's the case, it seems threads plus hygeinic macros and a few primitives a la Scheme would form a solid basis...
0
8632
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8985
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8849
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7661
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4341
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2273
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.