code is implemented by instantiating the object to call the class method. Now there is a new requirement. Without changing the business code, I want to add a decorator to execute the decorator function when calling the specific class method
Code example:
def decorater(func):
print("This function"s name is %s" % func.__name__)
def wrapper(*args,**kargs):
return func()
return wrapper
@decorater
class NEW():
def showTime(self):
print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))
def showName(self):
print("My name is Lee.")
NEW().showName()
NEW().showTime()
the above code is an example of a function decorating class that executes decorater, when the NEW object is instantiated. My goal is whether decorater? can be executed only when showName is called. Instead of executing it every time it is instantiated. Ask the gods who think no for help, thank you