Colons, indentation and reformatting.

P

Paddy

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/gener...equired-for-the-if-while-def-class-statements
.
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.

Tell me it is not so, or I will be editing the Wikipedia page I think.
And if it is true then do we need to update the FAQ?

- Paddy.
 
L

Leif K-Brooks

Paddy said:
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 it reindent this code?

if foo:
print "Foo!"
if bar:
print "Bar!"

Like this?

if foo:
print "Foo!"
if bar:
print "Bar!"

Or like this?

if foo:
print "Foo!"
if bar:
print "Bar!"
 
N

Neil Cerutti

How would it reindent this code?

if foo:
print "Foo!"
if bar:
print "Bar!"

Like this?

if foo:
print "Foo!"
if bar:
print "Bar!"

Or like this?

if foo:
print "Foo!"
if bar:
print "Bar!"

That's the key issue. The colon gives the editor an easy clue
where a block starts, but the there's no simply way to determine
where the block is supposed to end.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top