easydict:用属性的方法获取值
easydict
EasyDict可以让你像访问属性一样访问dict里的变量。
dic = {
"name":"regina",
"info":{
"age":23,
"addr":"shanxi"
}
}
print(dic["name"],dic['info']['age'])
正常情况下是这样访问字典内部数据的,但是我们希望可以通过dic.info.age
的方式获取会更方便一点,就要用到easydict模块
from easydict import EasyDict as edict
dic = {
"name":"regina",
"info":{
"age":23,
"addr":"shanxi"
}
}
easydic = edict(dic)
print(easydic.name)
print(easydic.info.age)
本文来自博客园,作者:ivanlee717,转载请注明原文链接:https://www.cnblogs.com/ivanlee717/p/17477782.html