![]() |
ATLAS Offline Software
|
Public Member Functions | |
| def | __init__ (self, *dicts) |
| def | __getitem__ (self, k) |
| def | __setitem__ (self, k, v) |
| def | __len__ (self) |
| def | __iter__ (self) |
| def | has_key (self, k) |
| def | copy (self) |
Public Attributes | |
| dicts | |
Allow lookups in multiple dictionaries while writing to one.
A StackedDict references a list of other dictionaries.
Reads try each dictionary in sequence, succeeding with the first dictionary
that contains the target key. Modifications go to the last dictionary
in the list.
Notes: No attempt is made to deal with keys duplicated between dictionaries;
len() and __iter__ will process them all. __delitem__ is not implemented.
Examples:
>>> from pprint import pprint
>>> d1 = {'a':'b'}
>>> d2 = {'c':'d'}
>>> d3 = {'e':'f'}
>>> d = StackedDict (d1, d2, d3)
>>> d['a']
'b'
>>> d['c']
'd'
>>> d['e']
'f'
>>> len(d)
3
>>> [x for x in d]
['a', 'c', 'e']
>>> 'c' in d
True
>>> 'c' in d
True
>>> 'd' in d
False
>>> d['c'] = 10
>>> d['c']
10
>>> d2
{'c': 10}
>>> d['x'] = 20
>>> d['x']
20
>>> pprint(d3)
{'e': 'f', 'x': 20}
>>> pprint(d.copy())
{'a': 'b', 'c': 10, 'e': 'f', 'x': 20}
Definition at line 14 of file StackedDict.py.
| def python.StackedDict.StackedDict.__init__ | ( | self, | |
| * | dicts | ||
| ) |
Definition at line 61 of file StackedDict.py.
| def python.StackedDict.StackedDict.__getitem__ | ( | self, | |
| k | |||
| ) |
Definition at line 66 of file StackedDict.py.
| def python.StackedDict.StackedDict.__iter__ | ( | self | ) |
Definition at line 86 of file StackedDict.py.
| def python.StackedDict.StackedDict.__len__ | ( | self | ) |
Definition at line 82 of file StackedDict.py.
| def python.StackedDict.StackedDict.__setitem__ | ( | self, | |
| k, | |||
| v | |||
| ) |
Definition at line 73 of file StackedDict.py.
| def python.StackedDict.StackedDict.copy | ( | self | ) |
Definition at line 104 of file StackedDict.py.
| def python.StackedDict.StackedDict.has_key | ( | self, | |
| k | |||
| ) |
Some code still uses this.
>>> d1 = {'a':'b'}
>>> d = StackedDict (d1)
>>> d.has_key ('a')
True
>>> d.has_key ('z')
False
Definition at line 92 of file StackedDict.py.
| python.StackedDict.StackedDict.dicts |
Definition at line 62 of file StackedDict.py.
1.8.18