python - Styling multi-line conditions in 'if' statements? -


sometimes break long conditions in ifs onto several lines. obvious way is:

  if (cond1 == 'val1' , cond2 == 'val2' ,       cond3 == 'val3' , cond4 == 'val4'):       do_something 

isn't very appealing visually, because action blends conditions. however, natural way using correct python indentation of 4 spaces.

for moment i'm using:

  if (    cond1 == 'val1' , cond2 == 'val2' ,           cond3 == 'val3' , cond4 == 'val4'):       do_something 

but isn't pretty. :-)

can recommend alternative way?

you don't need use 4 spaces on second conditional line. maybe use:

if (cond1 == 'val1' , cond2 == 'val2' ,         cond3 == 'val3' , cond4 == 'val4'):     do_something 

also, don't forget whitespace more flexible might think:

if (           cond1 == 'val1' , cond2 == 'val2' ,         cond3 == 'val3' , cond4 == 'val4'    ):     do_something if    (cond1 == 'val1' , cond2 == 'val2' ,         cond3 == 'val3' , cond4 == 'val4'):     do_something 

both of ugly though.

maybe lose brackets (the style guide discourages though)?

if cond1 == 'val1' , cond2 == 'val2' , \    cond3 == 'val3' , cond4 == 'val4':     do_something 

this @ least gives differentiation.

or even:

if cond1 == 'val1' , cond2 == 'val2' , \                        cond3 == 'val3' , \                        cond4 == 'val4':     do_something 

i think prefer:

if cond1 == 'val1' , \    cond2 == 'val2' , \    cond3 == 'val3' , \    cond4 == 'val4':     do_something 

here's style guide, (since 2010) recommends using brackets.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -