MCPcopy Index your code
hub / github.com/plotly/plotly.py / node_generator

Function node_generator

plotly/utils.py:132–162  ·  view source on GitHub ↗

General, node-yielding generator. Yields (node, path) tuples when it finds values that are dict instances. A path is a sequence of hashable values that can be used as either keys to a mapping (dict) or indices to a sequence (list). A path is always wrt to some object. Give

(node, path=())

Source from the content-addressed store, hash-verified

130
131
132def node_generator(node, path=()):
133 """
134 General, node-yielding generator.
135
136 Yields (node, path) tuples when it finds values that are dict
137 instances.
138
139 A path is a sequence of hashable values that can be used as either keys to
140 a mapping (dict) or indices to a sequence (list). A path is always wrt to
141 some object. Given an object, a path explains how to get from the top level
142 of that object to a nested value in the object.
143
144 :param (dict) node: Part of a dict to be traversed.
145 :param (tuple[str]) path: Defines the path of the current node.
146 :return: (Generator)
147
148 Example:
149
150 >>> for node, path in node_generator({'a': {'b': 5}}):
151 ... print(node, path)
152 {'a': {'b': 5}} ()
153 {'b': 5} ('a',)
154
155 """
156 if not isinstance(node, dict):
157 return # in case it's called with a non-dict node at top level
158 yield node, path
159 for key, val in node.items():
160 if isinstance(val, dict):
161 for item in node_generator(val, path + (key,)):
162 yield item
163
164
165def get_by_path(obj, path):

Callers 2

test_node_generatorMethod · 0.90
assert_dict_equalMethod · 0.90

Calls 1

itemsMethod · 0.45

Tested by 1

test_node_generatorMethod · 0.72