Are line continuations needed?

Derek Thomson derek at hiredgoons.org
Wed Apr 7 10:22:21 EDT 2004


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 ParticleDistributionBehaviorServer \
           (Microphysics__POA.ParticleDistributionBehavior):

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 ParticleDistributionBehaviorServer
                                             ^
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.



More information about the Python-list mailing list