'complex' function with string argument.

Skip Montanaro skip at pobox.com
Mon Mar 17 21:07:31 EDT 2014


On Mon, Mar 17, 2014 at 7:16 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Tue, Mar 18, 2014 at 10:59 AM, Skip Montanaro <skip at pobox.com> wrote:
>> Perhaps it's worth pointing out that pylint complains about most/many
>> infix operations if you don't surround the operator with white space.
>
> IMO that's excessive. Not every infix operator needs whitespace.

I wasn't suggesting it was the only way things could be done. Just
pointing out that there is enough common practice out there to suggest
that white space around infix operators is often the preferred way of
doing things. Quoting from PEP 8:

If operators with different priorities are used, consider adding
whitespace around the operators with the lowest priority(ies). Use
your own judgment; however, never use more than one space, and always
have the same amount of whitespace on both sides of a binary operator.

Yes:

i = i + 1
submitted += 1
x = x*2 - 1
hypot2 = x*x + y*y
c = (a+b) * (a-b)

...

My point is that accommodating white space around the + or - sign
isn't altogether unreasonable.

Maybe PEP 8 needs to be tweaked with an example of good complex
literal practice?

Skip



More information about the Python-list mailing list