A desperate lunge for on-topic-ness

Prasad, Ramit ramit.prasad at jpmorgan.com
Thu Oct 18 14:42:33 EDT 2012


Hans Mulder wrote:
> 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?
> 

For the first example, I would probably indent the arguments more 
to differentiate a continuing line. That way the "):" does not
look like it was un-indented to be part of a different block.

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)


Ramit Prasad



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  



More information about the Python-list mailing list