Python uses the dot operator to access Dictionary data.
This example describes how python uses the dot operator to access Dictionary (dict) data. Share it with you for your reference. The specific analysis is as follows:
Generally, the access to the dictionary is similar to: dict ['name'], if you can use dict. the following code defines a class to provide this method.
Class DottableDict (dict): def _ init _ (self, * args, ** kwargs): dict. _ init _ (self, * args, ** kwargs) self. _ dict _ = self def allowDotting (self, state = True): if state: self. _ dict _ = self else: self. _ dict _ = dict () d = DottableDict () d. allowDotting () d. foo = 'bar' print (d ['foo']) # barprint (d. foo) # bard. allowdoprint (state = False) print (d ['foo']) # bar from http://www.bkjia.comprint (d. foo) # AttributeError: 'dottabledict 'object has no attribute 'foo'
I hope this article will help you with Python programming.