瀏覽代碼

Add example to DictPath docstring

Alois Mahdal 10 年之前
父節點
當前提交
4d4d1666d7
共有 1 個檔案被更改,包括 21 行新增1 行删除
  1. 21
    1
      sznqalibs/hoover.py

+ 21
- 1
sznqalibs/hoover.py 查看文件

@@ -220,7 +220,27 @@ class RuleOp():
220 220
 class DictPath():
221 221
     """Mixin that adds "path-like" behavior to the top dict of dicts.
222 222
 
223
-    See TinyCase for description"""
223
+    Use this class as a mixin for a deep dic-like structure and you can access
224
+    the elements using a path.  For example:
225
+
226
+        MyData(dict, DictPath):
227
+            pass
228
+
229
+        d = MyData({
230
+            'name': 'Joe',
231
+            'age': 34,
232
+            'ssn': {
233
+                'number': '012 345 678',
234
+                'expires': '10-01-16',
235
+            },
236
+        })
237
+
238
+        print ("%s's ssn number %s will expire on %s"
239
+                % (d.getpath('/name'),
240
+                   d.getpath('/ssn/number'),
241
+                   d.getpath('/ssn/expiry')))
242
+        # joe's ssn number 012 345 678 will expire 10-01-16
243
+    """
224 244
 
225 245
     DIV = "/"
226 246