__init__() missing 1 required positional argument
Your constructor is expecting one parameter (data). You're not passing it in the call. I guess you wanted to initialise a field in the object. That would look like this:
class DHT:
def __init__(self):
self.data = {}
self.data['one'] = '1'
self.data['two'] = '2'
self.data['three'] = '3'
def showData(self):
print(self.data)
if __name__ == '__main__':
DHT().showData()
Or even just:
class DHT:
def __init__(self):
self.data = {'one': '1', 'two': '2', 'three': '3'}
def showData(self):
print(self.data)
You're receiving this error because you did not pass a data
variable to the DHT constructor.
aIKid and Alexander's answers are nice but it wont work because you still have to initialize self.data
in the class constructor like this:
class DHT:
def __init__(self, data=None):
if data is None:
data = {}
else:
self.data = data
self.data['one'] = '1'
self.data['two'] = '2'
self.data['three'] = '3'
def showData(self):
print(self.data)
And then calling the method showData like this:
DHT().showData()
Or like this:
DHT({'six':6,'seven':'7'}).showData()
or like this:
# Build the class first
dht = DHT({'six':6,'seven':'7'})
# The call whatever method you want (In our case only 1 method available)
dht.showData()