來源自 這裡
Preface :
A "shelve" is a persistent, dictionary-like object. The difference with "dbm" databases is that the values (not the keys!) in a shelve can be essentially arbitrary Python objects — anything that the pickle module can handle. This includes most class instances, recursive data types, and objects containing lots of shared sub-objects. The keys are ordinary strings.
Supported APIs :
Shelve objects support all methods supported by dictionaries. This eases the transition from dictionary based scripts to those requiring persistent storage. Besides, this module support below APIs :
- shelve.open(filename, flag='c', protocol=None, writeback=False)
- Shelve.sync()
- Shelve.close()
Restrictions :
The shelve module does not support concurrent read/write access to shelved objects. (Multiple simultaneous read accesses are safe.) When a program has a shelf open for writing, no other program should have it open for reading or writing. Unix file locking can be used to solve this, but this differs across Unix versions and requires knowledge about the database implementation used.
Example :
To summarize the interface :
Supplement :
* Persistent dictionary recipe
Preface :
A "shelve" is a persistent, dictionary-like object. The difference with "dbm" databases is that the values (not the keys!) in a shelve can be essentially arbitrary Python objects — anything that the pickle module can handle. This includes most class instances, recursive data types, and objects containing lots of shared sub-objects. The keys are ordinary strings.
Supported APIs :
Shelve objects support all methods supported by dictionaries. This eases the transition from dictionary based scripts to those requiring persistent storage. Besides, this module support below APIs :
- shelve.open(filename, flag='c', protocol=None, writeback=False)
- Shelve.sync()
- Shelve.close()
Restrictions :
The shelve module does not support concurrent read/write access to shelved objects. (Multiple simultaneous read accesses are safe.) When a program has a shelf open for writing, no other program should have it open for reading or writing. Unix file locking can be used to solve this, but this differs across Unix versions and requires knowledge about the database implementation used.
Example :
To summarize the interface :
Supplement :
* Persistent dictionary recipe
沒有留言:
張貼留言