[Tutor] Is there python editor or plugin for a python editor forcurly brackets around code blocks?

Alan Gauld alan.gauld at btinternet.com
Wed Aug 13 09:55:26 CEST 2008


"xbmuncher" <xboxmuncher at gmail.com> wrote

> visually see the code blocks as well as saves me constant pain when 
> the
> compiler complains about broken/missing indents in the code.*

Have you tried tabnanny that will fix up mixtures of tabs and
spaces - which is the most common cause of indentationn
errors in my experience

Personally I haven't had an indentation error in months. I just
get used to only using spaces.

> would be great if there was an editor for python or a plugin for an 
> existing
> program to be able to use curly brackets { } when defining code 
> blocks, and
> then maybe with a push of a button it can convert the curly bracket 
> style
> code that ignores indents to the indent sensitive code that the 
> python
> compiler wants.

There is a unix program called indent that does the indentation bit,
you would need to modify it to remove the braces (and of course
keep the braces on dictionary definitions!)

> times I'm constantly trying to hunt down indentation problems in 
> code
> (usually other people's code).

Really? Then I assume it didn't work in the first place?
Once code works you shouldn't get indentation errors unless
you modify it. (And thats where mixing tabs and spaces becomes
an issue and tabnanny can help.)

> Even visually a lot of people write their lines like this:
> def funcName(arg):
>    bla bla bla
>    more content of function
> if (this == that)
>    do this

Thats would be an errror if the condition is supposed
to be inside the function. So nobody should be writing code
like that! :-)

We often see that on the mailing list but its usually the
result of email reformatting in transit.

> Simple indentation errors can be a nightmare in determining whether 
> if
> statements and other code blocks are inside of another code block or 
> not....
> when all that seperates them is a single bad indent, which could be 
> the
> error you're looking for, or what it that way in the begg!

I agree it can be frustrating when dealing with other peoples
faulty code. I have had to struggle with that. But then, I've had to 
struggle
with that in C too because of the inconsistency of styles in C bracing
- single line blocks don;t need it, multi lines do. And the 
indentation
of braces is a huge cause for debate

if (foo) {
    code
    }

if (foo)
   {
       code
   }

if (foo)
{
    code
}

etc...

When different coders mix styles then working out whats intended
is at least as diffixcult as in Python IMHO.


> Also, another idea is to edit the compiler somehow or create
> soem kind of process/script that all scripts with teh curly
> brackets will get removed before being processed...

Good luck but I don;t think you'd have a chance of getting it
accepted officially. Most python users, me included, love the
absence of block markers! I'd even like to get rid of the colon!

Alan G. 




More information about the Tutor mailing list