Reputation: 11444
I am trying to create my own class of dictionary in python 3 which has a field of dict variable and setitem and getitem methods. Though, it doesnt work for some reason. Tried to look around but couldn't find the answer.
class myDictionary:
def __init(self):
self.myDic={}
def __setitem__(self, key, value):
self.myDic[key]=value
I'm getting:
'myDictionary' object has no attribute 'myDic'
Any ideas? :)
Upvotes: 0
Views: 305
Reputation: 10180
You've a typo within your __init__
method. Change it:
class myDictionary:
def __init__(self):
self.myDic={}
def __setitem__(self, key, value):
self.myDic[key]=valu
Upvotes: 1
Reputation: 208655
You forgot the trailing underscores on __init__()
, try the following:
class myDictionary:
def __init__(self):
self.myDic={}
def __setitem__(self, key, value):
self.myDic[key]=value
Upvotes: 2