makinacorpus / easydict

Access dict values as attributes (works recursively)
GNU Lesser General Public License v3.0
294 stars 47 forks source link

[suggestion] Better .get method #31

Open athossampayo opened 3 years ago

athossampayo commented 3 years ago

So, this is a simple suggestion, that I'm willing to contribute if more people believe it will be a good improvement: We should be able to access sub-elements on a Easydict with the method .get() from dict. Now this is the current behavior:

> dic = EasyDict({"first":{"second":{"third":"value"}}})
> dic.first.second.get("third")
'value'
> dic.first.get("second.third")
None

I beleive the correct behavior should be something in this line:

> dic.first.get("second.third")
'value'

Any ideas or comments on this idea?