Hi Can someone please help me understand this (i shouldn't have tried
to learn decorators and generators at the same time..).

Im trying to create a decorator that counts the number of times a
function is run.  Somthing like:

def FunctionCounter():
    n=0
    while 1:
        yield n
        n=n+1

def logFunctionCalls(function):
    print "Entering function:", function.__name__, ec.next()
    return function

@logFunctionCalls
def doWork():
    print "Doing Work"


doWork()

Where "ec" is a generator that is created inside logFunctionCalls if it
doesnt already exist.
Im thinking this has somthing to do with anonymous generators, but im
not sure how you create or access these..

Apologies in advance if this is moronic.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to