Therefore, I propose that as soon as practical, Python should enforce the following rules for horizontal whitespace:

All code indented with four spaces. This will also get rid of the tabs problem!

No redundant parentheses allowed (e.g. no "return(1)" where "return 1" would do).

No whitespace immediately following a left parentheses or immediately before a right parenthesis.

No whitespace before a left parenthesis that starts an argument list, or before a left square bracket that starts an index expression (e.g. "x[y]").

No whitespace before a comma or semicolon.

Exactly one space required after a comma or semicolon (except when at the end of a line).

No semicolon at the end of a line (it's redundant).

More than one consecutive space within an expression is never allowed.

Asignment and comparison operators must be surrounded by spaces.

The amount of whitespace on both sides of a binary operator should be the same.

If variable amounts of whitespace are used within an expression, this should correspond to the relative priorities of the operators used. For example: "1*2 + 3*4" is okay but "1*2 + 3 * 4" is not. However, "1*2+3*4" is still encouraged.

No space allowed before a colon.

In a dictionary display, exactly one space required after a colon. In a slice, none.

The short form of a block ("if x: y") is abandoned; you must use the newline-plus-indentation form.

A limited form of vertical whitespace fascism may also be introduced, although this may encounter more resistance, so it may be put off until Python 3.0:

At least one blank line should separate function or method definitions.

At least two blank lines should separate classes.

In order to give users sufficient time to adapt their coding style, the new syntax will be optional in Python 2.5, and required in Python 2.6. In Python 2.5, you can enable the strict whitespace checking for a particular module with a future statement:

RSS Feed

About the Blogger

Guido van Rossum is the creator of Python, one of the major
programming languages on and off the web. The Python community refers to him as the BDFL (Benevolent Dictator For Life), a title straight
from a Monty Python skit. He moved from the Netherlands to the USA in
1995, where he met his wife. Until July 2003 they lived in the
northern Virginia suburbs of Washington, DC with their son Orlijn, who
was born in 2001. They then moved to Silicon Valley where Guido now works for Google
(spending 50% of his time on Python!).