Persistent dictionary
asab.pdict.PersistentDict
¤
Bases: dict
The persistent dictionary works as the regular Python dictionary but the content of the dictionary is stored in the file.
You cat think of a PersistentDict
as a simple key-value store.
It is not optimized for a frequent access. This class provides common dict
interface.
Example
Warning
You must explicitly `load()` and `store()` content of the dictionary!
Warning
You can only store objects in the persistent dictionary that are serializable.
Source code in asab/pdict.py
__init__(path)
¤
Initialize persistent dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
Path for the dictionary file. |
required |
Source code in asab/pdict.py
load()
¤
store()
¤
update(other={}, **kwds)
¤
Update persistent dictionary from mapping or iterable.
Examples:
>>> pdict.update({'foo': 'bar', 'moo': 'buzz'})
>>> pdict.update(foo='bar', moo='buzz')
>>> pdict.update([('foo','bar'),('moo','buzz')])
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Dictionary or iterable of 2-tuples of the form (key, value) to be updated. |
{}
|