Object Oriented pubnub callback

I am trying to create a callback for a pubnub subscription. My pubnub implementation is wrapped in a class. I’d like to create a callback which can access the class fields. Normally you would pass self to the method, but the examples for callbacks at pubnub.com don’t account for this sort of pattern.

For example:

class Monitor(object):
 def __init__():
   self.lastMessage = ''
   pubnub.subscribe(channels=self.generateChannelName(), callback=callback,        error=error)
 def generateChannelName(self):
   return "name"
 def _callback(self,message, channel):
   self.lastMessage = message

 def _error(message):

The problem is that since we are passing the function itself to the subscribe method, we cannot stipulate that self be passed to it when invoked. Does anyone know how to use pubnub in an object oriented way? All the pubnub examples eschew OOP patterns (typical of python tutorials).

Source: oop

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.