README.rst edit
Dave Cinege
2 years ago
0 | 0 | Python Thesaurus and ThesaurusCfg |
1 | 1 | ========================================= |
2 | ||
3 | Python Thesaurus - "A different way to call a dictionary." | |
4 | ||
2 | 5 | Copyright (c) 2012-2019 Dave Cinege. All rights reserved. |
3 | 6 | |
4 | 7 | See the end of this file for further copyright and license information |
5 | 8 | |
6 | General Information | |
7 | ------------------- | |
8 | ||
9 | :Source code: https://git.cinege.com//thesaurus | |
9 | :Source code: https://git.cinege.com/thesaurus | |
10 | 10 | :Telegram Group: https://t.me/PythonThesaurus |
11 | ||
12 | At the moment there is no email list, wiki, etc. | |
13 | 11 | |
14 | 12 | |
15 | Quick start | |
16 | ------------ | |
17 | :: | |
13 | Quick Start | |
14 | ----------- | |
15 | ||
16 | .. code:: bash | |
18 | 17 | |
19 | 18 | $ python thesauruscfg_sample.py |
20 | 19 | |
23 | 22 | are all about. |
24 | 23 | |
25 | 24 | |
26 | Quick look | |
27 | ---------- | |
28 | :: | |
25 | Quick Overview | |
26 | -------------- | |
27 | ||
28 | .. code:: python | |
29 | 29 | |
30 | 30 | from thesaurus import thes, Keypath |
31 | 31 | t = thes() |
32 | 32 | t.set_path('a.b.c.d', 'Hello') |
33 | print(t['a']['b']['c']['d']) # as nested items | |
33 | print(t['a']['b']['c']['d']) # as nested keys | |
34 | 34 | print(t.a.b.c.d) # attribute aliasing |
35 | 35 | print(t.a.b['c'].d) # as both |
36 | kp = Keypath('a.b.c.d') | |
37 | print(t[kp]) # as a keypath | |
38 | 36 | |
39 | >>> 'a.b.c.d' in t | |
37 | kp = Keypath('a.b.c.d') # a keypath obj | |
38 | print(t[kp]) # keypath as the 'key' | |
39 | print('The value: {a.b.c.d}'.format(**t)) | |
40 | print(f'The value: {t.a.b.c.d}') # py3.6+ f-string. perfection! | |
41 | ||
42 | >>> 'a.b.c.d' in t # recursive contains | |
40 | 43 | True |
41 | >>> kp[:-2] in t | |
44 | >>> kp[:-2] in t # keypath slicing! (== 'a.b' in t) | |
42 | 45 | True |
43 | >>> print(kp) | |
46 | >>> print(kp) # keypath's str() dotted | |
44 | 47 | 'a.b.c.d' |
45 | 48 | >>> print(repr(kp)) |
46 | ['a', 'b', 'c', 'd'] | |
49 | ['a', 'b', 'c', 'd'] # but it's really like a list | |
47 | 50 | |
48 | 51 | |
49 | 52 | cfgs = ''' |
85 | 88 | so are you. |
86 | 89 | |
87 | 90 | ThesaurusExtended is a subclass of Thesaurus providing additional |
88 | usablity methods. | |
91 | usability methods such as recursive key and value searching. | |
89 | 92 | |
90 | 93 | ThesaurusCfg is a subclass of ThesaurusExtended providing a configuration |
91 | 94 | file parser and per key data coercion methods. |
130 | 133 | - Decide how to properly handle copying ThesaurusCfg coercion methods. |
131 | 134 | |
132 | 135 | - Resolve Thesaurus's schizophrenia. |
133 | :: | |
134 | ||
135 | v = t['a.b.c'] # This recurses | |
136 | t['a.b.c'] = v # This does not, needs set_path(). | |
137 | ||
138 | I want to be comfortable this feels natural to others or make changes. | |
136 | ||
137 | .. code:: python | |
138 | ||
139 | v = t['a.b.c'] # This recurses | |
140 | t['a.b.c'] = v # This does not, needs set_path(). | |
141 | ||
142 | I want to be comfortable this feels natural to others or find a | |
143 | better way. | |
139 | 144 | |
140 | 145 | |
141 | First Release Description from 2012 | |
146 | Early Release Description from 2013 | |
142 | 147 | ----------------------------------- |
143 | 148 | Thesaurus is a pure dictionary subclass which allows calling keys as |
144 | 149 | if they are class attributes and will search through nested objects |