Andrew's approach is good, but you could so something a little
simpler/more flexible.  Untested of course. :-)

Every callable object is followed by the args to pass it.  So this:
    debug_emit(DbgObjFoo(a, b, costly_function(c)))

becomes:
    debug_emit(DbgObjFoo, (a, b, costly_function, (c,)))

def debug_emit(*args):
    if not debug:
        return

    # assume last arg is not a callable and skip it
    i = len(args) - 2

    while i > 0:
        if callable(args[i]):
            # call it!  assume the next arg is a tuple of params
            new_value = args[i](*args[i+1])
            args = args[:i] + (new_value,) + args[i+2:]

    emit_dbg_code(*args)

cheers,
n

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

Reply via email to