So below is a non-working example that illustrates what I'm trying to get at
class TestClass(object):
def require_debug_mode(self, f):
def func_wrapper(*args, **kwargs):
if self.debug_mode:
return f(*args, **kwargs)
return func_wrapper
def __init__(self, debug_mode):
self.debug_mode = debug_mode
@require_debug_mode
def print_message(self, msg):
print msg
You could re-write the desired print_message
as the following:
def print_message(self, msg):
if self.debug_mode:
print msg
I essentially want to be able to decorate methods that will do certain checks (without having to repeat that check in every method that might use it). But these checks need access to instance level information. Is that even possible?