Request for tips on my first python script.

Roberto Bonvallet Roberto.Bonvallet at cern.ch
Fri Sep 8 11:36:18 EDT 2006


Lex Hider wrote:
> Any tips on the code quality and use of python would be appreciated. I've
> got a feeling the overall structure is up the creek.
[...]
>    for opt, arg in opts:
>        if opt in ("-l", "--latest"):
>            latest = int(arg)
>        elif opt in ("--notfound"):
>            ignoreNotFound = True #add notfound files to log 

Subtle bug here:  ("--notfound") is not a tuple, is just a string, so what
you are actually testing is whether opt is a substring of "--not-found".
To actually build a 1-element tuple, you have to put a trailing comma:

    elif opt in ("--notfound", ):

but it would be clearer if you just use:

    elif opt == "--notfound":

-- 
Roberto Bonvallet



More information about the Python-list mailing list