[Python-Dev] Suggested addition to PEP 8 for context managers
rosuav at gmail.com
Wed Apr 18 17:47:36 CEST 2012
On Thu, Apr 19, 2012 at 12:47 AM, Guido van Rossum <guido at python.org> wrote:
> I don't believe PEP 8 requires whitespace around all binary operators.
> Where do you read that?
Quoting from http://www.python.org/dev/peps/pep-0008/#other-recommendations
Use spaces around arithmetic operators:
x = x*2 - 1
hypot2 = x*x + y*y
c = (a+b) * (a-b)
In my code, whether Python or any other language, I tend to follow the
principle that whitespace is completely optional in these expressions,
but if spaces surround any operator, they should (generally) also
surround all operators of lower precedence in the same expression. So
I would quite happily accept all of the expressions above (except
'submitted', which is inconsistent), but would prefer not to see
c=(a + b)*(a - b)
which is also forbidden by PEP 8.
More information about the Python-Dev