Code reformater?

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Sat Jan 20 22:15:46 EST 2007


On Sat, 20 Jan 2007 23:51:24 -0300, Gabriel Genellina wrote:

> As the indentation *is* significant in python, none of the above can 
> help if you lose the indentation. Try to reconstruct this:
> 
> def foo():
> if a>0:
> if b>0:
> print 1
> print 2
> else:
> return 3
> return 4
> 
> The tools may help to make the indentation consistent (tabs/8 
> spaces/4 spaces/2 spaces mixed) or look better, but not to make it right.


Sure -- but a heuristic that gets it right *sometimes* may still be
useful, provided the user knows that the code may not be indented
correctly.

There are lots of legal Python blocks where the indentation CAN be
reconstructed correctly, and only a relatively small proportion where it
can't -- the tool could do its best, and warn the user when there are
indents that can't be dealt with. Or even refuse the temptation to guess,
but re-indent whatever parts of the code it is sure about.

Still, it is better not to lose the indentation in the first place.



-- 
Steven.




More information about the Python-list mailing list