could this be done using a decorator?
def func1(a, b):
c = a%b
return a * b + c
def func2(a, b):
c = a%b
return a - b * c
def func3(a, b):
c = a%b
return a + b + c
instead of having to specify c = a%b
in each of the functions,
i write
@deco
def func1(a, b):
return a * b
and it returns a * b + (a%b)
, one way to do it is,
def deco(func):
def wrapper(*args, **kwargs):
c = args[0] % args[1]
return func(*args, **kwargs) + c
return wrapper
but I would like to access the variable ‘c’ also, how do I access it?
func1.c
gives
AttributeError: 'function' object has no attribute 'c'
plus how do I access the function variables from outside the function, like, func1.a, func1.b
?