我有以下代碼。我正在嘗試使用滴答功能在扭曲的套接字中進行倒計時。它告訴我tick()只需要1個參數(0給定)。我該怎麼辦?完全參數1(0給出)
謝謝。
expire = 10
class Socket(Protocol):
def tick(self):
global expire
expire -= 1
if expire == 0:
print "Expired"
else:
reactor.callLater(1, self.tick)
def connectionMade(self):
#self.transport.write("""connected""")
self.factory.clients.append(self)
print "Clients are ", self.factory.clients
if len(self.factory.clients) == 1:
reactor.callLater(0, self.tick)
回溯:
Traceback (most recent call last):
File "/Users/Alec/Desktop/server.py", line 163, in <module>
class Socket(Protocol):
File "/Users/Alec/Desktop/server.py", line 171, in Socket
reactor.callLater(1, self.tick)
NameError: name 'self' is not defined
請用完整回溯顯示完整的錯誤信息。 – BrenBarn 2013-03-18 03:29:37
如果將'reactor.callLater(1,tick)'改爲'reactor.callLater(1,self.tick)',會發生什麼? – mgilson 2013-03-18 03:29:37
@mgilson Traceback(最近調用最後一次): 文件「/Users/Alec/Desktop/server.py」,第163行,在 class Socket(協議): 文件「/ Users/Alec/Desktop/server。 py「,第171行,插座號 reactor.callLater(1,self.tick) NameError:name'self'未定義 –
Alec
2013-03-18 03:31:29