sross at connectmail.carleton.ca
Thu Aug 28 01:38:59 CEST 2003
"Anthony Roberts" <anthonyr-at-hotmail-dot-com at nospam.com> wrote in message
news:Uva3b.49430$la.826046 at news1.calgary.shaw.ca...
> If I end indentation levels with "pass" statements, will I piss off people
> that have to read my code? eg:
> for i in xrange(0,5):
> if i:
> print i
> print i * -1
> I ask for two reasons... a) it helps emacs figure it out, and b) I'm more
> comfortable ending compound statements with a token.
Hi. I tried to do something like that too, early on. (I recall being
frustrated to find I couldn't just alias "end = pass", and use 'end' as a
block delimiter... heh). I didn't actually want to use 'end' (I like
significant whitespace), I just saw a lot of posts with complaints about
"no-block-delimiter", and I thought, I wonder if you can make one. Well, you
can (of course), but not like that.
Anyway. I think the suggested idiom for people who must have a visible block
delimiter is "# end <keyword>". If you use this, I think emacs can "figure
it out" (I don't know, I don't use emacs, but I think pymode can handle
this), and you can also use Tools/scripts/pindent.py, if you like.
# This file contains a class and a main program that perform three
# related (though complimentary) formatting operations on Python
# programs. When called as "pindent -c", it takes a valid Python
# program as input and outputs a version augmented with block-closing
# comments. When called as "pindent -d", it assumes its input is a
# Python program with block-closing comments and outputs a commentless
# version. When called as "pindent -r" it assumes its input is a
# Python program with block-closing comments but with its indentation
# messed up, and outputs a properly indented version.
# Secret feature:
# - On input, a block may also be closed with an "end statement" --
# this is a block-closing comment without the '#' sign.
Hmm. Looks like you can also use "end", or perhaps 'end' . I don't know if
the <keyword> is optional or not, having never used this module.
Anyway, if you use this format, then, if someone doesn't like seeing all
that noise when they read your code, they can strip it out with
"pindent -d". Handy. And, when you read other peoples code, you can clutter
it up nicely with "pindent -c". Best of both worlds, really.
More information about the Python-list