I have code that gets a list of all the functions in FooBarand a regular expression that the function supports in its parameter message:
functionList = []
def notify(RegExpression):
def _notify(function):
functionList.append((RegExpression, function))
return function
return _notify
class FooBar:
@notify(".*")
def everything(self, message):
pass
@notify("(\w+):.*")
def reply(self, message):
pass
for foo in functionList:
print("%s => %s" % foo)
I would like to do something similar, but list the list of functions and their parameters in the class as a class variable. This will prevent problems when more classes exist, such as FooBar. Each class must have its own list.
def notify(RegExpression):
class FooBar:
functionList = []
@notify(".*")
def everything(self, message):
pass
@notify("(\w+):.*")
def reply(self, message):
pass
for foo in FooBar.functionList:
print("%s => %s" % foo)
What is placed in notify()?
source
share