keeping Python code properly indented

John Roth newsgroups at
Fri Jan 16 04:12:22 CET 2004

<beliavsky at> wrote in message
news:3064b51d.0401151125.711ade4c at
> 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'.

Just about every editor in existence allows you to select a range
of lines and indent or dedent them as a group. If your editor
doesn't let you do this, get a better editor.

John Roth

More information about the Python-list mailing list