Passing parameters using **kargs

Aahz aahz at pythoncraft.com
Tue Jun 8 20:28:26 CEST 2004


In article <mailman.699.1086698522.6949.python-list at python.org>,
Terry Reedy <tjreedy at udel.edu> wrote:
>
>Or if you don't care, or want to intercept invalid calls.  Interestingly,
>the OP's example is the beginning of a possible debug wrapper usage where
>one either does not have a function's code or does not want to modify it
>directly.  Possible example:
>
>_f_orig = f
>def f(*largs, **kargs):
>  print 'f called with' largs, 'and', kargs
>  f(*largs, **kargs)

You mean

  _f_orig(*largs, **kargs)

I prefer this version:

def debugParams(func):
    def debugger(*args, **kwargs):
        for arg in args:
            print type(arg), arg
        for name in kwargs:
            value = kwargs[name]
            print name, type(value), value
        return func(*args, **kwargs)
    return debugger

f = debugParams(f)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha



More information about the Python-list mailing list