Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/carlosescri/DottedDict
Python library that provides a method of accessing lists and dicts with a dotted path notation.
https://github.com/carlosescri/DottedDict
Last synced: about 2 months ago
JSON representation
Python library that provides a method of accessing lists and dicts with a dotted path notation.
- Host: GitHub
- URL: https://github.com/carlosescri/DottedDict
- Owner: carlosescri
- License: mit
- Created: 2014-03-07T18:29:00.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-02-27T22:31:32.000Z (over 1 year ago)
- Last Synced: 2024-02-29T22:33:20.745Z (4 months ago)
- Language: Python
- Homepage:
- Size: 227 KB
- Stars: 173
- Watchers: 4
- Forks: 25
- Open Issues: 12
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.txt
- License: LICENSE
Lists
- awesome-python - dotteddict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- Awesome-Python - dotted - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - DottedDict - Python library that provides a method of accessing lists and dicts with a dotted path notation. (Awesome Python / Built-in Classes Enhancement)
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- python-awesome-case1 - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- fucking-awesome-python - :octocat: DottedDict - :star: 168 :fork_and_knife: 25 - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python-master - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome_python - dotted - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- join-awesome-python-interview-topics - dotted - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python-cn - DottedDict
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python-clone - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python-resources-all - dotted - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python-master - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- fucking-awesome-python - :octocat: DottedDict - :star: 105 :fork_and_knife: 14 - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python-zh - DottedDict - 一个库,它提供了一种使用点路径表示法访问列表和dicts的方法。 (内置类增强功能)
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesomePython - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python-resources - GitHub - 77% open · ⏱️ 30.10.2015): (内置类的增强版实现)
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- python-awesome - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - dotted - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome_python_with_star - carlosescri/DottedDict
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- git-github.com-vinta-awesome-python - dotted - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - dotted - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - dotted - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - dotted - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python - DottedDict - A library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement)
- awesome-python-cn - DottedDict
- awesome-python - DottedDict - Python library that provides a method of accessing lists and dicts with a dotted path notation. (Built-in Classes Enhancement [🔝](#readme))
README
dotted
======.. image:: https://pypip.in/version/dotted/badge.svg?style=flat
:target: https://pypi.python.org/pypi/dotted/
:alt: Latest Version
.. image:: https://travis-ci.org/carlosescri/DottedDict.svg?branch=master
:target: https://travis-ci.org/carlosescri/DottedDictA Python library that provides a method of accessing lists and dicts with a
dotted path notation. It is useful to access a deep path inside a complex
object composed of lists and dicts.Quick & Dirty:
==============.. code-block:: python
from dotted.collection import DottedCollection, DottedDict, DottedList
obj = DottedCollection.factory(dict_or_list)
obj = DottedCollection.load_json(json_value)
obj = DottedDict(a_dict)
obj = DottedList(a_list)from dotted.utils import dot, dot_json
obj = dot(dict_or_list)
obj = dot_json(json_value)``DottedDict`` and ``DottedList`` have the same accessors as ``dict`` and ``list``
so you can iterate them as usual. Both type of objects support access via a
dotted path key.Examples
========Example #1: DottedList
----------------------.. code-block:: python
obj = DottedList([0, 1, 2, 3, [4, 5, 6], 7, 8, [9, 10]])
All of these are true:
.. code-block:: python
obj[0] == 0
obj['1'] == 1
obj['4.0'] == 4
obj['4.2'] == 6
obj[5] == 7
obj['7.1'] == 10If you want to append you can do:
.. code-block:: python
obj.append(12)
or:
.. code-block:: python
obj[8] = 11
but the latter only works if ``index == len(obj)``. In other case you will get a
very pretty exception.Example #2: DottedDict
----------------------.. code-block:: python
obj = DottedDict({'hello': {'world': {'wide': 'web'}}})
All of these are true:
.. code-block:: python
obj['hello'] == {'world': {'wide': 'web'}}
obj['hello.world'] == {'wide': 'web'}
obj['hello.world.wide'] == 'web'obj.hello == {'world': {'wide': 'web'}}
obj.hello.world == {'wide': 'web'}
obj.hello.world.wide == 'web'Example #3: Both working together
---------------------------------.. code-block:: python
obj = DottedCollection.factory({
'hello': [{'world': {'wide': ['web', 'web', 'web']}}]
})You can access:
.. code-block:: python
obj['hello'][0]['world']['wide'][0]
obj.hello[0].world.wide[0]
obj.hello[0].world['wide'][0]
obj.hello[0].world['wide.0']
obj.hello['0.world'].wide[0]
...
obj['hello.0.world.wide.0']Example #4: When new values are dicts or lists
----------------------------------------------.. code-block:: python
obj = DottedCollection.factory(some_obj)
obj['some.path'] = {'hello': 'world'} # will be converted to a DottedDict
obj['another.path'] = ['hello'] # will be converted to a DottedListExample #5: Shortcuts
---------------------.. code-block:: python
from dotted.utils import dot, dot_json
obj = dot({'hello': 'world'})
obj = dot_json('{"hello": "world"}')Example #6: Keys with dots inside!
----------------------------------Well, you can actually use escaped keys, but it's better to avoid them:
.. code-block:: python
from dotted.utils import dot, dot_json
obj = dot({"hello\.world": "Hello!"})
obj = dot_json('{"hello\\\\.world": "Hello!"}')
value = obj["hello\.world"] # Hello!That's all!
Tests
=====Run in the terminal from the parent directory:
.. code-block:: console
python -m dotted.test.test_collection
Special Thanks
==============- **Marc Abramowitz** (`@msabramo`_)
- **Ryan Witt** (`@ryanwitt`_).. _@msabramo: https://github.com/msabramo
.. _@ryanwitt: https://github.com/ryanwitt