keeping Python code properly indented

Thomas Heller theller at python.net
Thu Jan 15 14:38:41 EST 2004


beliavsky at aol.com writes:

> How do you keep Python code properly indented as you modify it? I use
> an Emacs-type editor that has a Python mode, so the initial indenting
> is easy. If I later want to put a 'for' loop (or an 'if' statement)
> around a bunch of code, I find myself going through the body of the
> loop, manually re-indenting to keep the nested loops correct. There
> should be a better way.
>
> I think that having a 'for' loop end with a matching 'next' statement,
> as done in (for example) Basic, is a safer and clearer way of writing
> loops, although some Python programmers consider this a 'feature'
> rather than a 'bug'.

In Xemacs with python-mode, I just mark the region and hit 'C-c >'
py-shift-region-right or 'C-c <' py-shift-region-left.

Thomas



More information about the Python-list mailing list