Quantcast
Channel: How to use a dot "." to access members of dictionary? - Stack Overflow
Viewing all articles
Browse latest Browse all 40

Answer by IRSHAD for How to use a dot "." to access members of dictionary?

$
0
0

Use __getattr__, very simple, works in Python 3.4.3

class myDict(dict):    def __getattr__(self,val):        return self[val]blockBody=myDict()blockBody['item1']=10000blockBody['item2']="StackOverflow"print(blockBody.item1)print(blockBody.item2)

Output:

10000StackOverflow

Viewing all articles
Browse latest Browse all 40

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>