View Single Post
Old Aug 13th, 2006, 11:38 AM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,869
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
I'm guessing it's meant for debugging, to see how many times a function is being called. The only thing, is there's no argument to handle the function as a parameter. Once I added that in, and a default for "inc", I could make a demonstration.

def make_acc(func, start=0):
    """accumulator generator """
    curr = [start]
    def acc(inc=1):
        curr[0] += inc
        return curr[0]
    return acc

@make_acc # use make_acc for debugging purposes
def foo():
    return "bar"

print foo() #1
print foo() #2
print foo() #3
print foo() #4


# don't use "make_acc" 
def foo():
    return "bar"

print foo() #bar
print foo() #bar
print foo() #bar
print foo() #bar
So basically, you would append that decorator to any function, and instead of it being called, it will return how times it has been called.
Sane is offline   Reply With Quote