Significant whitespace

Steven D'Aprano steve at
Sat Jan 2 13:03:28 CET 2010

On Sat, 02 Jan 2010 10:42:39 +0000, Duncan Booth wrote:

> Donn <donn.ingle at> wrote:
>> On Saturday 02 January 2010 00:02:36 Dan Stromberg wrote:
>>> I put together a page about significant whitespace (and the lack
>>> thereof).
>> The only thing about Python's style that worries me is that it can't be
>> compressed like javascript can*, and perhaps that will prevent it
>> becoming a browser-side language one day. How I'd love to code PyQuery
>> instead of JQuery!
> You can do simple white-space removal as easily in Python as in
> Javascript, you just need to maintain a minimal indentation and as you
> don't need Javascript's curly braces there probably isn't must
> difference especially once the code has been gzipped for transfer to the
> browser.

I don't understand why you would bother removing whitespace, particularly 
if you're going to gzip the file anyway.

I've just picked one of my modules at random: about 47K in size, of which 
about 15K is whitespace. Compressed to .bz, it is 12K, and if I strip the 
whitespace from it first and then compress it, it is 11K.

So, even though whitespace (spaces and newlines) make up about 30% of the 
original source, once compressed they represent only about 8%. Given the 
extra complexity of stripping whitespace, I don't know that it's 
worthwhile. It's not like you're going to reduce the download time from 
three hours to one; it's more like 2 seconds to 1.5.


More information about the Python-list mailing list