Indentation
Tim Chase
python.list at tim.thechases.com
Wed May 26 16:54:25 EDT 2010
On 05/26/2010 03:13 PM, William Miner wrote:
> I have a script which I would now put inside a loop. Is there
> any way to ³automatically² indent the old script so it can be
> put inside the new loop. Doing it by hand seems so inelegant
> and time consuming.
It's usually a function of your editor -- most good editors allow
you to indent/exdent a block of code. In vim (my editor of
choice), you can use the ">" and "<" operators with a motion or
visual block to indent one 'shiftwidth' (which uses spaces or
tabs based on your 'expandtab' setting, and can mix-and-match if
your 'tabstop' isn't the same as your 'shiftwidth').
Adam already demonstrated how to do it in MonoDevelop, and I
think in Visual Studio (a long time since I've had to touch that
beast) you can just highlight a block and press <tab> or
<shift+tab> to indent/exdent. Likely an emacs user will chime in
on this thread with how to do it there too.
If you're stuck with a bogus editor but are on a *nix platform,
you can indent with sed:
sed 's/^/ /' original.py > out.py
(that's 4 spaces after the 2nd slash; adjust accordingly to your
tastes) and then just copy the contents of out.py into your script.
If you're on Win32 without a good editor, go get a good editor ;-)
-tkc
More information about the Python-list
mailing list