A Suggestion for Python Colon Syntax

Nathaniel Gray n8gray at nospam.nospam
Thu Dec 21 23:09:32 CET 2000

William Djaja Tjokroaminata wrote:

> Hi all,
> I have been using Python for some time, and I have a suggestion for the
> Python Colon (:) syntax.
> [snip suggestion for removing the colon (what an evocative sentence!)]
> Any comments, anyone?

I understand this problem of forgetting to care for your colons, but 
perhaps seeking to change the language is the wrong path.  Although "colon 
neglect" is a common problem, I don't think you'll find a lot of support 
for purging the colon, particularly from Guido.  Without Guido's support 
there's just no hope of changing Python's syntax.

What you might consider instead is customizing your text editor.  Write a 
macro that gets executed every time you hit enter that does the following 
with the previous line:
1.  If the first word is not {if, for, def, etc...} then return
2.  Ignore all comments for the following three steps
3.  If there is a colon on the line already, return
4.  If the last character on the line is "\" then return
5.  If the parens, brackets, and braces don't balance then return
6.  Insert a colon after the last non-comment character

Note that this is just a first stab at the problem and it definitely won't 
always work right (e.g. multi-line strings), but it will cure 90% of colon 
neglect cases without a Python parser or a costly hospital visit.  
Extending it to work for multi-line "colon statements" is left as an 
excercise for the reader.

If you're stuck with an editor that you can't or don't know how to tweak, 
try NEdit (http://www.nedit.org) instead.  It has a nice Python mode and is 
imminently scriptable.

maybe-they-shoulda-called-it-the-appendix-instead-ly y'rs  -  n8

             Nathaniel Gray
   California Institute of Technology
     Computation and Neural Systems
     n8gray <at> caltech <dot> edu

More information about the Python-list mailing list