A desperate lunge for on-topic-ness

wxjmfauth at gmail.com wxjmfauth at gmail.com
Thu Oct 18 05:33:07 EDT 2012


Le jeudi 18 octobre 2012 11:07:25 UTC+2, Hans Mulder a écrit :
> 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

I use a "double indentation".

>>> if 'asdf' and 'asdf' and 'asdf' \
...         'asdf' and 'asdf' and \
...         'asdf' and 'asdf':
...     print('do if')
...     s = 'asdf'
...     ss = 'asdf'
...     
do if
>>> 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)
...     
Traceback (most recent call last):

jmf



More information about the Python-list mailing list