目录
easydict的简介
EasyDict允许访问dict值作为属性(递归工作)。python dicts的类似Javascript的属性点表示法。
easydict的安装
pip install easydict
easydict的使用方法
1. >>> from easydict import EasyDict as edict 2. >>> d = edict({'foo':3, 'bar':{'x':1, 'y':2}}) 3. >>> d.foo 4. 3 5. >>> d.bar.x 6. 1 7. 8. >>> d = edict(foo=3) 9. >>> d.foo 10. 3 11. 12. 13. >>> from easydict import EasyDict as edict 14. >>> from simplejson import loads 15. >>> j = """{ 16. "Buffer": 12, 17. "List1": [ 18. {"type" : "point", "coordinates" : [100.1,54.9] }, 19. {"type" : "point", "coordinates" : [109.4,65.1] }, 20. {"type" : "point", "coordinates" : [115.2,80.2] }, 21. {"type" : "point", "coordinates" : [150.9,97.8] } 22. ] 23. }""" 24. >>> d = edict(loads(j)) 25. >>> d.Buffer 26. 12 27. >>> d.List1[0].coordinates[1] 28. 54.9