Coding style - keep brackets on one line or new line?

Suppose you call a function where it is clearly necessary to split the statement into several lines, for readability. However, there are at least two ways to do this:

You would do this:

return render(request, template, { 'var1' : value1, 'var2' : value2, 'var3' : value3 } ) 

Or you would rather do this:

 return render \ ( request, template, { 'var1' : value1, 'var2' : value2, 'var3' : value3 } ) 

Or please suggest your own formatting. Also indicate the reasons why you use specific formatting and what is wrong with the other.

thanks

+6
python coding-style formatting readability
source share
4 answers

I would probably do:

 return render( request, template, { 'var1' : value1, 'var2' : value2, 'var3' : value3 } ) 

I would keep the bracket in one line, so a render( search render( will work. And because I find it clearer. But I would put all the arguments in new lines.

+8
source share

The official Python PEP-8 offers the first option.

+9
source share

I would do:

 vars = { 'var1' : value1, 'var2' : value2, 'var3' : value3, } return render(request, template, vars) 
+7
source share

The second looks like he escaped from C [# +] *. The continuation of the backslash line is ugly, prone to problems with finite space, and there is no excuse to use it when you have () or [] to use.

+2
source share

All Articles