Code review request

Gerald Britton gerald.britton at gmail.com
Wed Dec 22 15:29:18 EST 2010


Hi Jason,

There are a couple of things that I noticed:

1. You might want to check out PEP 8  -- a Python style guide.  Among
other things, some lines are very long and you are not consistent with
putting a space after a comma in a list or between arguments in a
function call.

e.g.

opts, args = getopt.getopt(argv,
"hlsr:e:i:d",["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="])

That's 125 characters, not including the indentation!  You can break
it up and even make it more readable like this:

opts, args = getopt.getopt(
                       argv,
                       "hlsr:e:i:d",

["Help","list-emplys","select","remove-emply=","edit-emply=","insert-emply="]
                       )

but then the embedded list is still too long.  It can also be split like this:

opts, args = getopt.getopt(
                       argv,
                       "hlsr:e:i:d",
                       ["Help", "list-emplys", "select", "remove-emply=",
                        "edit-emply=", "insert-emply="]
                       )

Just do it so that it's easy to read and support.  Notice the commas
are followed by spaces in the list.

In the listEmployees function (check out PEP 8 about naming
conventions, while you're at it!) there is one line that could be
simpler:

print "%s, %s, %s, %s" % (lst[0],lst[1],lst[2],lst[3])

could be:

print "%s, %s, %s, %s" % tuple(lst[:4])

or if the number of elements could be more or less, you could even do this:

for item in lst:
  print item,

which should do the same thing (the trailing comma suppresses the new
line) and you'll never have to count the number of items in lst.

You also have some statements like:

sqlchk = "select * from employees where id = \"%s\"" % (arg)

Since a Python list can be enclosed in apostrophes as well as
quotations, you can get the same thing without the escapes:

sqlchk = 'select * from employees where id = "%s"' % (arg)


Anyway -- just some food for thought.

-- 
Gerald Britton



More information about the Python-list mailing list