TypeError: __init__() missing 2 required positional arguments: 'client_socket' and 'statusMessage'

后端 未结 2 1901
遥遥无期
遥遥无期 2020-12-06 13:59
import socket
import sys

class SimpleClient:
    def __init__(self, client_socket, statusMessage):
        self.client_socket = client_socket
        self.statusMes         


        
相关标签:
2条回答
  • 2020-12-06 14:07
    class SimpleClient:
        def __init__(self, client_socket, statusMessage):
    

    Your class taking two arguments, but when you call it;

    client = SimpleClient()
    

    You didn't write any arguments. So you have to put 2 arguments they may be None.

    0 讨论(0)
  • 2020-12-06 14:27

    If you want to allow passing no arguments to the Class initiator, you have to define the initiator with default values set to None (or whatever is appropriate).

    For example,

    def __init__(self, client_socket=None, statusMessage=""):
        self.client_socket = client_socket
        self.statusMessage = statusMessage
    

    Now you can call your class instantiation without passing initialization parameters.

    client = SimpleClient()
    
    0 讨论(0)
提交回复
热议问题