Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > PEP8, line continuations and string formatting operations

Reply
Thread Tools

PEP8, line continuations and string formatting operations

 
 
Gerald Britton
Guest
Posts: n/a
 
      01-21-2011
Style question:

PEP 8 suggests that line continuations be done by enclosing
expressions in parentheses rather than using the line continuation
character. In the same paragraph, it states a preference to put
binary operators at the end of the line to be continued, so:

x = (a +
b)

is preferred over:

x = (a
+ b)

Fair enough.

What about string formatting operations (old style) though? The %
symbols is a binary operator between a string and the substitution
values. Strictly reading PEP 8 leads to:

my_string = ("A long string with %s substitutions that %s the line
should be %s." %
("many", "suggest", "continued")
)

However, I often see the % on the continued line, immediately
preceding the substitution variables, like this:

my_string = ("A long string with %s substitutions that %s the line
should be %s."
% ("many", "suggest", "continued")
)

This goes against the PEP 8 guidelines, but I prefer it since it makes
the substitution variables "jump out" a bit more -- at least to me.

So....what's the general feeling about this? Adhere to the PEP 8
binary operators style, or modify it for string formatting?


--
Gerald Britton
 
Reply With Quote
 
 
 
 
Carl Banks
Guest
Posts: n/a
 
      01-21-2011
On Jan 21, 11:53*am, Gerald Britton <(E-Mail Removed)> wrote:
> So....what's the general feeling about this? Adhere to the PEP 8
> binary operators style, or modify it for string formatting?


Well, personally I ignore the "operator at end of first line"
guideline altogether; I think it's much more readable with the
operator on the following line, not even close.

I'm starting to not fold lines with parentheses as much, either.
Sometimes the parentheses break the flow too much, or suggest grouping
where it isn't desirable.


Carl Banks
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
String Formatting Operations for decimals. Lacrima Python 1 04-01-2010 09:14 AM
method to intercept string formatting % operations bradallen Python 3 02-05-2010 08:53 PM
stand-alone JMS, other JDBC operations, and transactions ( ActiveMQ + JOTM + JDBC operations ) Jesus M. Salvo Jr. Java 2 02-11-2006 06:33 PM
RE: Are line continuations needed? Batista, Facundo Python 9 04-09-2004 08:42 AM
Are line continuations needed? Russell Wallace Python 13 04-08-2004 12:47 PM



Advertisments