次のコードがあります。dataReceived メソッドで、テーブルにアクセスしようとしていますが、エラーが発生します。self を使用してそのすべてを実行すると機能しますが、 self を使用したくありません。self を使用しても、私の目的には適していません。self を使用せずにテーブルにアクセスするにはどうすればよいですか?
ありがとう!
class Table:
def __init__(self):
self.players = []
self.positions = []
self.id = 0
self.numberOfPlayers = 0
def setID(self, _id):
self.id = _id
def setActivePlayer(self, player):
player.countdown = 20
while player.count > 0:
print player.countdown
time.sleep(1)
player.countdown -= 1
if player.countdown == 0:
print "Out of time"
moves.surrender(player)
class Socket(Protocol):
table = Table()
def connectionMade(self):
#self.transport.write("""connected""")
self.factory.clients.append(self)
print "Clients are ", self.factory.clients
def connectionLost(self, reason):
self.factory.clients.remove(self)
def dataReceived(self, data):
#print "data is ", data
a = data.split(':')
if len(a) > 1:
command = a[0]
content = a[1]
b = content.split(';')
_UDID = b[0].replace('\n', '')
if command == "Number_of_Players":
if Socket.table.numberOfPlayers == 0:
msg = "%s:TableFound" % _UDID
elif Socket.table.numberOfPlayers == 1:
msg = "%s:Table_Not_Found" % _UDID
print msg
for c in self.factory.clients:
c.message(msg)
def message(self, message):
self.transport.write(message)
NUM_TABLES = 10
factories = [ ]
for i in range(0, NUM_TABLES):
print i
factory = Factory()
factory.protocol = Socket
factory.clients = []
factories.append(factory)
reactor.listenTCP(1025+i, factory)
#print "Blackjack server started"
reactor.run()