Colons, indentation and reformatting.

Discussion in 'Python' started by Paddy, Jan 9, 2007.

  1. Paddy

    Paddy Guest

    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.
     
    Paddy, Jan 9, 2007
    #1
    1. Advertising

  2. 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!"
     
    Leif K-Brooks, Jan 9, 2007
    #2
    1. Advertising

  3. Paddy

    Neil Cerutti Guest

    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
     
    Neil Cerutti, Jan 9, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven Livingstone

    __doPostback method with colons problem

    Steven Livingstone, Aug 4, 2003, in forum: ASP .Net
    Replies:
    15
    Views:
    746
    John Saunders
    Aug 28, 2003
  2. Grant Robertson

    Multiple colons in namespace names?

    Grant Robertson, Jan 13, 2007, in forum: XML
    Replies:
    6
    Views:
    683
    Joe Kesselman
    Jan 15, 2007
  3. Paddy
    Replies:
    9
    Views:
    298
    Hendrik van Rooyen
    Jan 10, 2007
  4. Jesse B.
    Replies:
    2
    Views:
    197
    Josh Cheek
    Mar 27, 2010
  5. Québec
    Replies:
    6
    Views:
    143
    Thomas 'PointedEars' Lahn
    Nov 17, 2003
Loading...

Share This Page