A desperate lunge for on-topic-ness

Hans Mulder hansmu at xs4all.nl
Thu Oct 18 05:07:00 EDT 2012


On 18/10/12 08:31:51, Steven D'Aprano wrote:
> On Thu, 18 Oct 2012 02:06:19 -0400, Zero Piraeus wrote:
>> 3. Say "well, at least it's not a backslash" and break the line using
>> > parentheses.
> I mostly do this. Since most lines include a bracket of some sort, I 
> rarely need to add outer parentheses just for the purpose of line 
> continuation.
> 
> some_variable = spam('x') + ham(
>                     some_longer_variables, here_and_here, 
>                     and_here_also)

I would spell that as:

some_variable = spam('x') + ham(
    some_longer_variables,
    here_and_here,
    and_here_also,
)

> I know PEP 8 says I should drop the final round bracket to the next line, 
> but I don't normally like that.

I normally put the final bracket on the next line, where it is
very visible.  Compare:

if looks_like_it_might_be_spam(
    some_longer_variables,
    here_and_here, and_here_also):
    logger.notice("might be spam")
    move_to_spam_folder(some_longer_variables)
    update_spam_statistics(here_and_here)

vs.

if looks_like_it_might_be_spam(
    some_longer_variables,
    here_and_here,
    and_here_also,
):
    logger.notice("might be spam")
    move_to_spam_folder(some_longer_variables)
    update_spam_statistics(here_and_here)

Which one would you say is more readable?


-- HansM



More information about the Python-list mailing list