ライブラリ紹介[2/100]: easydict
前書き
今回は、easydictを紹介します。
easydict
辞書オブジェクトの値に属性としてアクセスすることが可能になります。
インストール
pip install easydict
使い方
辞書オブジェクトをEasyDictでラップします。
>>> numbers = {"one": 1, "two": 2, "three": 3} >>> numbers["one"] 1 >>> numbers.one Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'dict' object has no attribute 'one' >>> from easydict import EasyDict >>> enumbers = EasyDict(numbers) >>> enumbers.one 1
辞書オブジェクトで値に属性としてアクセスしようとするとAttributeError
が発生します。
後書き
お疲れ様でした。次回も違うライブラリを紹介します。