[Tutor] Sharpening the print statement (was:Readlines(longish!))

David Broadwell dbroadwell@mindspring.com
Fri Jun 27 00:29:01 2003


Alan Gauld wisely typed;
> print statements are powerful debugging tools but they are a
> very blunt instrument and can obfuscate as much as they reveal
> if overused.

This is pretty much all snipped to uselessness, but hopefully still
shows the intent of having a easy to change debug 'mode'. This snippet
is from 'pwsdb' a little password file data base I whipped up that
really isn't a database.

>>> start here

mode = 2 # execution mode, see readme. .config?
         # 0 = print nothing, return password, script entry
         # 1 = print error messages
         # 2 = print messages *default
         # 3 = print debug location messages
         # 4 = print logic checking debug messages
         # 5 = print everything, including list and object states

def read(filename,key,command):
   '''
   if (mode >= 3): print "Debug: read(%s, %s, %s)" % (filename, key,
command)
   if (mode >= 2): print readmessage
   if command == "!cli":
      if not filename: filename = getfile(filename)
      if not key: key = hashkey(getkey(key))
   load(filename)
   if key == pwsfile[2]: # if get.hashkey matches load.haskey
      if (mode >= 3): print "Debug: Read; valid file and valid key"
      pwsfile[4] =
crunch(pwsfile[4],pwsfile[2],'decrypt',configdes[2],configdes[0],configdes[3
])
      if (mode >= 1):
         print "Your decrypted password for file %s is %s" % (filename,
pwsfile[4])
      if (mode == 0):
         myexit(pwsfile[4])
      myexit("Success: Password is " + pwsfile[4])
   else:
      myexit("Failure: Bad Key, goodbye.")

>>> enough out of context code ... hope it dosen't kill it with the line
wrapping

Read the comments with each 'mode' setting above, any commentary on the
overall method? (short and long term view)

The style developed as i used print statements to debug but then found i
didn't need them. But after a while of commenting and uncommenting and
commenting and uncommenting and deleteing and retyping and commenting ... I
found a easier way to make a sweeping debug mode ...

--

David Broadwell