I am trying to add more variables inside the initialization bracket after importing a module and I get an error,__init__ takes 3 positional arguments but four were given. How do I fix this?
#Module1
class(first):
def __init__(self, word, count):
self.word = word
self.count = 0
from Module1 import first
class second(first):
def __init__(self, word, count, option):
super().__init__(word, count, option)
def new(word):
types = type(word)
if types == str:
print(word)#if the word is a string print the word
count += 1#increment the value to 1
option1 = "first attempt"
word1 = "coding"
result = second(word1, 0, option1)
res = result.new(word1)
print(res)
I am getting an error(TypeError: __init__() takes 3 positional arguments but 4 were given )
>Solution :
You can add the attribute option to the class second:
class first(object):
def __init__(self, word, count):
self.word = word
self.count = 0
class second(first):
def __init__(self, word, count, option):
super().__init__(word, count)
self.option = option
def new(self, word):
types = type(word)
if types == str:
print(word) # if the word is a string print the word
self.count += 1 # increment the value to 1
option1 = "first attempt"
word1 = "coding"
result = second(word1, 0, option1)
res = result.new(word1)
print(res)