Poss :
I created this small program. It should add to the cupboard some products. I get the following error:
TypeError: add_prod() missing 1 required positional argument: 'product'.
Here is the code:
class Products:
def __init__(self,nome):
self.nome = nome
class Cupboard:
def __init__(self):
self.prod = []
def add_prod(self, product):
self.prod.append(product)
def show(self):
print(self.prod)
p1 = Products("Ajax")
p2 = Products("Barilla")
Cupboard.add_prod(p1)
Cupboard.add_prod(p2)
show()
Mark Loeser :
In your code when you are trying to add Products
to Cupboard
, you are trying to do it to the class itself instead of to an instance. You should create an instance of Cupboard
first like you did for Products
:
p1 = Products("Ajax")
p2 = Products("Barilla")
c1 = Cupboard()
c1.add_prod(p1)
c1.add_prod(p2)
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=375761&siteId=1