Colons, indentation and reformatting. (2)

Paddy paddy3118 at netscape.net
Tue Jan 9 02:17:00 EST 2007


mensanator at aol.com wrote:

> Paddy wrote:
> > I was just perusing a Wikipedia entry on the "off side rule" at
> > http://en.wikipedia.org/wiki/Off-side_rule .
> > It says that the colon in Python is purely for readability, and cites
> > our FAQ entry
> > http://www.python.org/doc/faq/general.html#why-are-colons-required-fo...
> >  .
> > However, near the top of the Alternatives section, it states that for C
> > type, curly braces using languages:
> >   "An advantage of this is that program code can be automatically
> > reformatted and neatly indented without fear of the block structure
> > changing".
> >
> > Thinking about it a little, it seems that a colon followed by
> > non-indented code that has just been pasted in could also be used by a
> > Python-aware editor as a flag to re-indent the pasted code.
>
> How would you re-indent this?
>
> if x>0: print x
If pasted as a line , after a line *ending with* a colon then indent it
w.r.t. previous line.
if pasting full lines after such a line then first pasted line cannot
be indented more than this line; if it is then flag for re-indenting
pasted block either equal too or less than this line.

- Paddy.




More information about the Python-list mailing list