Vote count:
0
I have a client-server program I'm making, and essentially I have the Client class, which requires 3 arguments, self,host and port. However, when I attempt to create an instance of the client class I get this error.
TypeError: init() takes 1 positional argument but 3 were given
I don't understand, am I not asking for three arguments, and sending it three? What am I missing here? If you guys could help that would be amazing!
import socket
import threading
import random
class Client():
def __init__(self,host,port) :
self.host = host
self.port = port
class Server() :
def __init__(self) :
self.host = '127.0.0.1'
self.port = 6000
self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.clients = {}
self.games = {}
def Initiate(self) :
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind((self.host,self.port))
self.socket.listen(6)
print('Server has Started')
while True :
self.Scout()
def Scout(self) :
self.clients[len(self.clients)] = self.socket.accept()
print('Connection from : %s'%(str(self.clients[len(self.clients)-1][1])))
self.clients[len(self.clients)-1] = Client(self.clients[len(self.clients)-1][1][0],self.clients[len(self.clients)-1][1][1])
return 'New Connection'
asked 11 secs ago
Python : __init__ asks for three arguments, yet when I call it claims it requires one argument?
Aucun commentaire:
Enregistrer un commentaire