python newbie: some surprises

J. Cliff Dyer jcd at sdf.lonestar.org
Fri May 9 11:42:14 EDT 2008


On Fri, 2008-05-09 at 15:08 +0000, Yves Dorfsman wrote:
> Gabriel Genellina wrote:
> 
> >> I see the point of the OP. Couldn't the new-line be used as an 
> >> equivalent of   ':', for example, do you find this difficult to read:
> >>
> >> if a == 3
> >>    do_something()
> >>
> >>
> >> if a == 3: do_something()
> > 
> > Yes, it could be done, there are no technical reasons to always force to 
> > use ":". But AFAIK the main reasons to keep ":" are internal consistency 
> > (an inner block always starts with ":"; incidentally, that's easier to 
> > handle for editors) and legibility (the ":" stands for itself and has a 
> > meaning)
> 
> Legibility ?
> But one could make the same argument for curly brackets, and we seem to be 
> doing fine without them !
> 
> I have become so used to the power of indenting in python that I keep 
> forgetting the colon, and this is getting worse as I do more python, not 
> better. Maybe I'll write myself a "pre-compiler" that add the colons where 
> the compiler needs them :-)
> 
> 
> Yves.
> http://www.SollerS.ca
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

Have you considered the following:

if (x == 4 and (y in 
    [len(x) for x in
    foo if x**2 > 23]
    or y < 2) and z.strip().endswith('z') and
    remove_first(w))
    attach_list(q, r)
    reject(x)

A colon on the correct line would help readability quite a bit.

Yeah, I know I made it pretty ugly to begin with, and there are ways to
improve it without the colon, but still, just because it could be
removed doesn't necessarily mean it should.

Cheers,
Cliff




More information about the Python-list mailing list