Oh no, my code is being published ... help!

Tim Roberts timr at probo.com
Fri Nov 30 01:19:38 EST 2007


rm <rmcorrespond at gmail.com> wrote:
>
>The thing is I am starting to get a little nervous about it.  You see,
>programming is not my full time job.  I dabble in it from time to
>time, mostly to scratch my own itches, as they say.  But, I know that
>my code is probably far from being of professional quality.  So, I was
>wondering if some of you would be interested in taking a peak and
>offer some suggestions for improving the quality and safety of the
>code.  Let me try to explain what they do.

There are several places where you do something like this:
    strng = "abcde"
    print str(strng)

Why the calls to str()?  These are already strings, and even if they
weren't, "print" will convert its arguments.

You also have a couple of instances of:
    print("Error Squeezing %s...")

The parentheses serve no purpose here, and are unidiomatic.

You have:
    if ErrorHalt == True:
In almost every case, it's better to write this as:
    if ErrorHalt:

The same applies to:
    if debug == 1:
This is really a boolean, and most would write that as:
    if debug:

"Tuple" is spelled with one "p", but that's being awfully picky...

Note that this:
    def Save(self):
        LogFile = open(self.logpath, "w")
        for line in self.LogStrings:
            LogFile.write(line)
        LogFile.close()
can be written as:
    def Save(self):
        open(self.logpath, "w").writelines( self.LogStrings )
but that's really micro-optimization.

Most people would argue that every line in a log file should be written and
flushed to disk immediately, and not saved until some later time.  If your
program terminates unexpectedly, all of your log information will be lost.

You assume that p7zip will be installed in /usr/bin/7za.  That's not good.
On many of my systems, I install all new packages into /usr/local/bin. Some
people use /opt.  You should really check the PATH to look for 7za.
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list