I can not access the dictionary keys with dot(.) but when I define a class that inherits from dict, I can access its keys using dot(.). Can anybody explain it?
So, when I run this code:
d = {'first_key':1, 'second_key':2}
d.first_key
I get this error:
'dict' object has no attribute 'first_key'
but when I run this:
class DotDict(dict):
pass
d = DotDict()
d.first_key = 1
d.second_key = 2
print(d.first_key)
print(d.second_key)
I get this:
1
2