E
Ethan Furman
Emile van Sebille wrote:
so this line ^ becomesUsing a decorator works when named arguments are not used. When named
arguments are used, unexpected keyword error is reported. Is there a
simple fix?
Extend def wrapper(*args) to handle *kwargs as well
Emile
Code:
-----
from functools import wraps
def fix_args(fn):
@wraps(fn)
def wrapper(*args):
def wrapper(*args, **kwargs):
and add a lineargs = (arg.replace('_', '') for arg in args)
for k, v in kwargs:
kwargs[k] = v.replace('_', '')
and this line ^ becomesreturn fn(*args)
return fn(*args, **kwargs)
return wrapper
~Ethan~
Ethan,
I tried you code suggestions but got errors.
Right, my 'for k, v in kwargs' should have been 'for k, v in kwargs.items()'
Glad you were able to make it work!
~Ethan~