Why indentation is use to denote block of code?
milesck at umich.edu
Mon Sep 14 09:50:46 CEST 2009
On Sep 13, 2009, at 5:38 PM, AggieDan04 wrote:
> On Sep 13, 6:27 pm, Steven D'Aprano wrote:
>> On Sun, 13 Sep 2009 15:15:40 -0700, Chris Rebert wrote:
>>> In fact it's pretty much impossible to automatically indent Python
>>> that has had its indentation removed; it's impossible to know for
>>> where the dedents should occur.
>> Just like most other syntactic elements -- if you remove all the
>> statements from Python code, or dot operators, it's impossible to
>> automatically add them back in.
>> The only difference is that some (badly written?) applications mangle
>> leading whitespace, but very few feel free to remove other text on
>> a whim.
>> I don't recall actually using a mail client or newsreader that
>> leading whitespace when posting, but I've occasionally seen posts
>> others with all indentation removed, so presumably such badly-behaved
>> applications do exist.
> I haven't seen it in a mail client, but it's very common in internet
If you regularly deal with some sort of transport that messes with
your leading whitespace, you may find Tools/scripts/pindent.py in the
Python source distribution useful; it adds comments that act as block
closers to your code, and can then use those comments to restore the
correct indentation to a mangled version. (Most forums offer some
sort of whitespace-preserving [code] tag, though; and pindent is
relatively old, and apparently not well maintained (no support for
More information about the Python-list