Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Colons, indentation and reformatting.

Reply
Thread Tools

Colons, indentation and reformatting.

 
 
Paddy
Guest
Posts: n/a
 
      01-09-2007
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/genera...ass-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.

 
Reply With Quote
 
 
 
 
Leif K-Brooks
Guest
Posts: n/a
 
      01-09-2007
Paddy wrote:
> 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!"
 
Reply With Quote
 
 
 
 
Neil Cerutti
Guest
Posts: n/a
 
      01-09-2007
On 2007-01-09, Leif K-Brooks <> wrote:
> Paddy wrote:
>> 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!"


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.

--
Neil Cerutti
Remember in prayer the many who are sick of our church and community. --Church
Bulletin Blooper
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
remove overall indentation preserving reletive indentation Jesse B. Ruby 2 03-27-2010 07:23 PM
Colons, indentation and reformatting. (2) Paddy Python 9 01-10-2007 05:31 AM
multiline strings and proper indentation/alignment John Salerno Python 11 05-10-2006 06:23 PM
automatic nesting and indentation in emacs porterboy Python 3 02-25-2005 01:54 PM
How to get VIM indentation and Python playing nicely? Kenneth McDonald Python 1 06-14-2004 12:32 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57