PEP 8 : Maximum line Length :
Ben Finney
ben at benfinney.id.au
Tue May 13 08:10:11 EDT 2014
Ganesh Pal <ganesh1pal at gmail.com> writes:
> what would be the best way to intent the below line .
You'd need to define “best” in order to get an objective answer.
So my answer will be based on my preferences, and general rules I've
observed for making code readable.
> Example 1 :
>
> p =
> Subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
(Your example violates PEP 8 also in not having a space after the
commas. I'll fix that in my response.)
Breaking a long line after bracketing syntax is a good way to do it.
Make sure to use sntadard indentation::
Subprocess.Popen(
shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Alternatively, if the statement line is indented further::
Subprocess.Popen(
shlex.split(cmd),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
> Iam running pylint and it says the above line is tool long how do I limit
> it to 79 character without violating any rules
* Break after bracketing syntax::
frobnicate(
foo, bar, baz)
* Keep all the inside-the-brackets contents at the same indentation
level (preferably 8 columns, to differentiate from a block of
statements)
if worzel:
fnoop(wibble, wobble, wubble)
frobnicate(
foo, bar, baz)
while True:
gezunk()
Here's an answer I gave on StackOverflow for this question
<URL:http://stackoverflow.com/questions/5931297/how-would-you-properly-break-this-line-to-match-pep8-rules/17246180#17246180>
(<URL:http://stackoverflow.com/a/17246180/70157>).
--
\ “If you're a cowboy and you're dragging a guy behind your |
`\ horse, I bet it would really make you mad if you looked back |
_o__) and the guy was reading a magazine.” —Jack Handey |
Ben Finney
More information about the Python-list
mailing list