PEP 8 and extraneous whitespace

Andrew Berg bahamutzero8825 at
Thu Jul 21 19:51:00 CEST 2011

Hash: RIPEMD160

I found a couple things that I think should be tweaked in PEP 8. I don't
agree with everything in PEP 8, but I'm not going to debate /those/
points; rather I'm bringing up a couple examples that violate PEP 8, but
don't apply to the reasons given for their violation. In PEP 8, it says
to avoid extraneous whitespace. For example, this is bad (example taken
from PEP 8):
if x == 4 : print x , y ; x , y = y , x
No need for the extra spaces. But, it makes sense to have extra
whitespace when aligning items in say, a dictionary assignment:
categories = {
			'main'   : Category(),
			'input'  : Category(),
			'avs'    : Category(),
			'ffmpeg' : Category(),
			'video'  : Category(),
			'audio'  : Category(),
			'x264'   : Category()

PEP8 makes no mention of dictionary assignments, which leads me to think
this was an oversight.

Another example, this time with commas:
self.x264_cmd = (
	self.x264_exe,  self.avs_file,
	'--fps',        self.fpsr,
	'--sar',        self.sar,
	'--crf',        self.crf,
	'--level',      self.level,
	'--min-keyint', self.minki,
	'--ref',        self.ref,
	'--weightp',    self.weightp,
	'--bframes',    self.bframes,
	'--b-adapt',    self.badapt,
	'--merange',    self.merange,
	'--trellis',    self.trellis,
	'--subme',      self.subme,
	'--deblock',    self.deblock,
	'--output',     self.video_output
Looks nice all lined up, but it violates PEP 8 because of those extra
spaces, which is only because extra spaces look bad in one-line
assignments that have nothing to do with lists/tuples or dictionaries.
This is one of those times not to follow PEP 8 to the letter, but it
does trip up checker programs (which are useful for catching silly
things like an extra space at the end of a line or missing spaces around
operators). Thoughts?

- -- 
CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla -


More information about the Python-list mailing list