__init__() missing 1 required positional argument

前端 未结 6 1660
死守一世寂寞
死守一世寂寞 2020-12-06 09:35

I am trying to learn Python. This is a really simple code. All I am trying to do here is to call a class\'s constructor. Initialize some variables there and print that varia

6条回答
  •  鱼传尺愫
    2020-12-06 10:22

    The problem is with, you

    def __init__(self, data):
    

    when you create object from DHT class you should pass parameter the data should be dict type, like

    data={'one':1,'two':2,'three':3}
    dhtObj=DHT(data)
    

    But in your code youshould to change is

    data={'one':1,'two':2,'three':3}
    if __name__ == '__main__': DHT(data).showData()
    

    Or

    if __name__ == '__main__': DHT({'one':1,'two':2,'three':3}).showData()
    

提交回复
热议问题