PEP 8 and extraneous whitespace

Thomas 'PointedEars' Lahn PointedEars at web.de
Thu Jul 21 21:40:01 EDT 2011


Dan Sommers wrote:

> bruno.desthuilliers at gmail.com wrote:
>> 1/ you can consider the equal sign ('=') is the "binding operator".
>> 
>> 2/ since {'key':'val'} is equivalent to dict(key=val), you can consider
>> colons as a binding operator here
> 
> But PEP 8 (under Other Recommendations) indicates spaces around the
> former but not the latter:
> 
>     key = val
>     dict(key=val)
> 
> We all know that there should be one-- and preferably only one --obvious
> way to do it.  But what do we also know about foolish consistency?

I do not know what you *think* we all know, and I do not quite see your 
point. 

I for one have pondered this question and have found the suggestion in the 
PEP a reasonable one, for if you use a function call in the RHS of an 
assignment the lack of whitespace around the equals sign for the keyword 
argument makes it easier to see the final assignment:

  d = dict(key=val)

vs.

  d = dict(key = val)

vs.

  d = key = val

YMMV.

-- 
PointedEars

Bitte keine Kopien per E-Mail. / Please do not Cc: me.



More information about the Python-list mailing list