List Comprehension Syntax

Peter Hansen peter at engcorp.com
Mon Jul 12 13:12:49 EDT 2004


Ville Vainio wrote:

>>>>>>"Peter" == Peter Hansen <peter at engcorp.com> writes:
> 
> 
>     Peter> But if you let emacs define the limits of your world, then
>     Peter> it's probably okay to do it that way.  ;-)
> 
> It's just the path of least resistance - any other indentation
> requires manual work, and won't reindent properly when pressing <tab>
> on the line.

Not sure what you mean here.  The indentation approach I'm
referring to (i.e. the "standard" way, as opposed to what I
was calling the "artistic" way) is just to hit tab in precisely
the same way you would if you were indenting an "if" block.

> Anyway, the point is mostly moot because
> 
> blah = [
>     i + 1
>     for i in range(10)
>     if i != 3
>     ]
> 
> indents the way you want it to, and that's the way I usually do it
> anyway. I just M-x indent-region'ed your code snippet :).

Not sure which code-snippet you refer to, but the ones that I
typed were indented the same way, except perhaps that I put
the first expression the same line as the opening bracket.

> Perhaps this is something that could be fixed in python-mode.el? I
> mean making the indentation on the next line be previous_line + 4 in
> bracket-opening situations... Or is the current behaviour better in
> some generally agreed way?

Nope, definitely not in a generally agreed way.  I don't think anyone
thinks this issue is on par with the tab war though, so until that
particular war is won, we're best off leaving this issue to personal
preference.  (That is to say, "forever". :-)

-Peter



More information about the Python-list mailing list