loop does not count...

Terry Reedy tjreedy at udel.edu
Thu Nov 13 10:41:22 EST 2003


"Jonathan Driller" <jdriller at orchid.org> wrote in message
news:a8cff9fb.0311121513.521ca948 at posting.google.com...
> I am very new to this

A common newbie programmer mistake, having read 'comment your code',
is to overcomment to the point of giving a parallel plain-text version
of the code, as you did.   Your worse example of this is

>     #initialize counter at 0
>     i = 0

The result is to make the code harder and more painful to read,
especially for an experienced programmer, rather than easier, which is
the proper purpose of comments. If you are going to write a parallel
psuedocode version, make it truly parallel by using your space key (or
tab key in editor that converts to spaces) to put the comments over to
the right:

     i = 0
#initialize counter at 0

Then someone can much more easily ignore the redundant comments to
read the actual code.

There is no need to read urlList.txt twice.
    z = open('urlList.txt')
    urlList = z.readlines()
 can be replaced by
   urlList = urlFile.split('\n')

Unless you need to write code for 1.5.2, I recommend you learn now to
write string methods as methods rather than as string module
functions.  The latter is a redundant access path for backwards
compatibility that will probably disappear in the future.  If you look
in the string module, you will find, for instance, def count(s,
*args): return s.count(*args), so all you are doing is wrapping the
method calls in an extra function call.

I hope Johm's answer is the one you needed.

Terry J. Reedy







More information about the Python-list mailing list