Reputation: 439
I've got a class defined with a method to add items to it:
class ProdReg:
def __init__(self):
self.__PListe=[]
def addProdukt(self,pItem):
self.__Pliste.append(pItem)
When I instantiate a ProdReg object and try to add an object to it with the following code i gent an error:
pr.addProdukt(b)
I get the following error:
AttributeError: 'ProdReg' object has no attribute '_ProdReg__Pliste'
What's wrong? I'm not able to figure thisone out.
/Andy.l
Upvotes: 0
Views: 260
Reputation: 193696
It's a typo in your code I think, or a misunderstand of how names work. In Python names are case-sensitive.
You add the attribute as PListe
then reference it as Pliste
. In one in the L
is lower case and in the other it is upper case.
Upvotes: 3
Reputation: 131647
Because in the __init__
you wrote: __PListe
and in the the addProdukt
method, you wrote __Pliste
. Python is case sensitive.
Upvotes: 6