[Twisted-Python] Permanent Object
I want to create a server in twisted that has a permanent variable which i want to use as the number of request requested to the server. When i use that for Protocol, each time the variable is created newly. Then i used *class Echo(Protocol): def dataReceived(self, data): if "data" not in dir(self.factory): self.factory.data = 0 self.factory.data = self.factory.data + 1 """As soon as any data is received, write it back.""" self.transport.write(data + str(self.factory.data)) but i want to remove the code that is: ** if "data" not in dir(self.factory): self.factory.data = 0 self.factory.data = self.factory.data + 1 How to do that? *
On Tue, 5 Aug 2008 17:13:41 +0530, Squzer Crawler <squzer@declum.com> wrote:
I want to create a server in twisted that has a permanent variable which i want to use as the number of request requested to the server. When i use that for Protocol, each time the variable is created newly.
Then i used *class Echo(Protocol): def dataReceived(self, data):
if "data" not in dir(self.factory): self.factory.data = 0 self.factory.data = self.factory.data + 1
"""As soon as any data is received, write it back.""" self.transport.write(data + str(self.factory.data))
but i want to remove the code that is:
** if "data" not in dir(self.factory): self.factory.data = 0 self.factory.data = self.factory.data + 1
How to do that? *
Why? You said it's what you wanted. Jean-Paul
participants (2)
-
Jean-Paul Calderone
-
Squzer Crawler