Newbie (but improving) - Passing a function name with parameters as a parameter

mosscliffe mcl.office at googlemail.com
Thu May 10 04:27:18 EDT 2007


I am trying to time a function's execution, but I get 'TypeError:
'bool' object is not callable' when I try to run it.

I suspect it is my calling of 'timeloop' with the function name
'lookup' and its associated variables or it could just be some stupid
error on my part.

function 'lookups' was working OK

Any help will be appreciated.

Thanks - Richard

===The offending Code =====


#!/usr/bin/python

def timeloop(dofunction,iters=10):
   import datetime
   print "->-> Start of test", "LOOPS=", iters,
datetime.datetime.now().ctime()
   for x in xrange(iters):
      print x
      dofunction()
   print "<-<- End of test", "LOOPS=", iters,
datetime.datetime.now().ctime()



def lookup(recs,patterns):
   matchcount = 0
   pattcount = 0
   for patt in patterns:
      if matchcount < pattcount:
         break
      pattcount += 1
      for rec in recs:
         # print "PATT:", patt, " REC:", rec, " PATTCOUNT=", pattcount
         if patt in rec:
            matchcount +=1
            break
   # print"MATCHCOUNT=",matchcount, "PATTCOUNT=", pattcount
   if matchcount == pattcount:
      return True
   else:
      return False



myrecs = ['This is a title for Brian', 'this is detail one for brian',
'this is detail two for brian', 'this is another detail one for
brian']

test1 = ['one', 'nomatch']
test2 = ['one', 'two']
test3 = ['title', 'two', 'nomatcheither']

mypatts = test1

timeloop(lookup(myrecs,mypatts), 10)




More information about the Python-list mailing list