class idDict(dict):
def __getattr__(self,key):
return 'dsaads'
d=idDict()
print d['ss']
I just get an error: KeyError: 'ss'. According to some online forums, this should work.
I want to print out ‘dsaads’
This doesn’t work either; I get the same error:
from collections import defaultdict
class idDict(defaultdict):
def __getattr__(self,key):
return 'dsaads'
d=idDict()
print d['ss']
use
__getitem__: