Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71478

Re: PEP 8 : Maximum line Length :

From Ben Finney <ben@benfinney.id.au>
Subject Re: PEP 8 : Maximum line Length :
Date 2014-05-13 22:10 +1000
References <CACT3xuWxJHqqV26R+3aYvpovRs7OZ6_TFynSVV-n-b+EkMmtKA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.9960.1399983026.18130.python-list@python.org> (permalink)

Show all headers | View raw


Ganesh Pal <ganesh1pal@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: PEP 8 : Maximum line Length : Ben Finney <ben@benfinney.id.au> - 2014-05-13 22:10 +1000

csiph-web