dict_digger-0.2.1
توضیحات
Useful syntax for digging into nested dictionaries, lists and tuples, and removes the need to check if a key exists
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | dict_digger-0.2.1 |
| نام | dict_digger |
| نسخه کتابخانه | 0.2.1 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Jonathan Tushman |
| ایمیل نویسنده | jonathan@zefr.com |
| آدرس صفحه اصلی | https://github.com/jtushman/dict_digger |
| آدرس اینترنتی | https://pypi.org/project/dict_digger/ |
| مجوز | MIT |
dict_digger
===========
Digs into Dicts
Useful syntax for digging into nested dictionaries, lists and tuples, and removes the need to check if a key or index exists, or handling of
KeyError or IndexError
Installation
------------
.. code-block:: bash
$ pip install dict_digger
Usage
-----
.. code-block:: python
import dict_digger
h = {
'a': {
'b': 'tuna',
'c': 'fish'
},
'b': {}
}
result = dict_digger.dig(h, 'a','b')
print result # prints 'tuna'
result = dict_digger.dig(h, 'c','a')
print result # prints None
# Important!! Does not through an error, just returns None
#but if you like
result = dict_digger.dig(h, 'c','a', fail=True)
# raises a KeyError
# also support complex objects so ...
complex = {
'a': {
['tuna','fish']
},
'b': {}
}
result = dict_digger.dig(complex, 'a',0)
print result #prints tuna
Alternatives
------------
.. code-block:: python
try:
result = h['c']['a']
except KeyError:
result = None
Testing
-------
We are using nose
.. code-block:: bash
$ nosetests
نحوه نصب
نصب پکیج whl dict_digger-0.2.1:
pip install dict_digger-0.2.1.whl
نصب پکیج tar.gz dict_digger-0.2.1:
pip install dict_digger-0.2.1.tar.gz