def mention_notifier(self):
print self.stat_old
if __name__ == "__main__":
import sys
self.stat_old = Set([])
l = task.LoopingCall(mention_notifier).start(timeout)
This is the basic skeleton of my code. I want stat_old to be a global variable that doesn’t get re intialized every time I call mention_notifier. Thus, I did something like this. But got this error of ‘self’ not defined. Any clues how to go about this?
I don’t use Twisted, but from looking at the docs, something like this might work:
Of course, here the variable name
selfshould probably be changed to something else — by conventionselfis typically used inside of classes to reference the instance of the class in a method call …It looks like
LoopingCallcan be given arguments to be passed along to the function (in this case, the Namespace objectselfis passed). Then inside the function, “self” is modified (as long as you don’t do something likeself=...inside the function, you’re golden —self.attribute=...is completely fine)