Indentation for code readability

John Machin sjmachin at lexicon.net
Fri Mar 30 05:32:56 EDT 2007


On Mar 30, 7:04 pm, "DE" <devrim.er... at gmail.com> wrote:
> Hello,
>
> Here is what I do in C++ and can not right now in python :
>
> pushMatrix()
> {
>      drawStuff();
>
>      pushMatrix();
>      {
>             drawSomeOtherStuff()
>      }
>      popMatrix();}
>
> popMatrix();
>
> The curly brackets have no functional meaning but increase the
> readability significantly. I want to be able to do the same thing in
> python. Since curly brackets are not available and indenting without
> an if or while conditional doesn't work, I have started to question if
> this is possible in python at all.
>
> Any ideas ?
>

You *can* use round brackets and/or square brackets. E.g.

def pushMatrix():
    drawStuff()
    pushMatrix()
    (
        drawSomeOtherStuff()
    )
    [
        drawEvenMoreStuff()
    ]
    popMatrix()

Whether you *should* do that is a different question ... It's a bit
like an English definition of a Scottish gentleman: one who can play
the bagpipes, but doesn't :-)

HTH,
John




More information about the Python-list mailing list