Question regarding commenting code
Chris Barker
chrishbarker at home.net
Thu Sep 6 13:16:21 EDT 2001
Andrew Gould wrote:
>
> When adding comments to scripts, can I insert lines of comments inside a
> loop block? For example:
>
> for n in a_list:
> # separate values using spaces as delimiters
> a_line = string.split(n)
> # get the first value
> a_value = a_line[0]
> # print the first value
> print a_value
of course, this is legal (comments are ignored by the interpreter, but I
have a couple of comments (yuk, yuk).
A) you are over commenting, but for a newbie, it may be OK
B) it will be a lot more readable if you indent you comments along with
the code. Remember that in Python , the indentation defines the block
structure:
for n in a_list:
# separate values using spaces as delimiters
a_line = string.split(n)
# get the first value
a_value = a_line[0]
# print the first value
print a_value
C) relating to B): in emacs Python mode (I don't know about other
editors, comments with a single # will influence the auto indentation. I
you do want to put a comment in that doesn't effect the indentaion, you
need to use two #s (##)
-Chris
--
Christopher Barker,
Ph.D.
ChrisHBarker at home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------
More information about the Python-list
mailing list