[Tutor] String formatting

VanL vlindberg@verio.net
Fri, 15 Feb 2002 16:10:56 -0700


Hello,

I can't figureout why this is dying on me:

#!/usr/bin/env python

[snip]

totalfiles = 0
includedfiles = 0
changedfiles = 0
textchanges = 0

[snip]

def main():

    # Get options
    optlist, args = getopt.getopt(sys.argv[1:], 's:r:u:F:D:R:X:I:ABqh', 
['usage', 'help', 'binary'])
    opts = getAllOptions(optlist)

   
    if not opts['quiet']:
        # Grab statistical variables
        global totalfiles
        global includedfiles
        global changedfiles
        global textchanges
   
        if totalfiles > 0 and includedfiles > 0:
            stat1 = ((includedfiles * 1.0)/totalfiles)
            stat2 = ((changedfiles * 1.0)/totalfiles)
            stat3 = ((changedfiles * 1.0)/includedfiles)
        else:
            stat1, stat2, stat3 = 0, 0, 0
        percent = '%'
        print '%(totalfiles)s total files, %(includedfiles)s included in 
content scan  (%(stat1)s%(percent)s)' % vars()
        print '%(changedfiles)s files changed (%(stat2)s%(percent)s of 
total files, %(stat3)s%(percent)s of scanned files)' % vars()
        print '%s total text changes' % textchanges  



This is giving me a keyerror for totalfiles.

Could anyone tell me  why?

Thanks,

Van