[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
server, either in flat pickle files or in a shelve-based database. Both raise the specter of concurrent updates, since any numbe ...
...
PART V Tools and Techniques This part of the book presents a collection of additional Python application topics. Most of the too ...
...
CHAPTER 17 Databases and Persistence “Give Me an Order of Persistence, but Hold the Pickles” So far in this book, we’ve used Pyt ...
Pickled objects Serialized Python objects saved to files and streams Shelve files Pickled Python objects saved in DBM keyed file ...
DBM Files Flat files are handy for simple persistence tasks, but they are generally geared toward a sequential processing mode. ...
(4, True, b'Wham!') >>> file.close() # close sometimes required Internally, importing the dbm standard library module a ...
Robin Bang! >>> file['Batman'] = 'Ka-Boom!' # change Batman slot >>> del file['Robin'] # delete the Robin entr ...
DBM Details: Files, Portability, and Close Despite the dictionary-like interface, DBM files really do map to one or more externa ...
Recent changes: Be sure to also pass a string 'c' as a second argument when calling dbm.open, to force Python to create the file ...
new process, this difference is often irrelevant (though as we saw in Chapter 5, this generally precludes using pickled objects ...
Any object that provides these attributes can be passed in to the file parameters. In particular, file can be an instance of a P ...
The object you get back from unpickling has the same value and reference structure as the original, but it is located at a diffe ...
C:\...\PP4E\Dbase>python >>> from filepickle import * >>> table = loadDbase('myfile') # reload/unpickle > ...
Pickle Details: Protocols, Binary Modes, and _pickle In later Python releases, the pickler introduced the notion of protocols—st ...
Refer to Python’s library manual for more information on the pickler; it supports ad- ditional interfaces that classes may use t ...
Using Shelves In other words, shelve is just a go-between; it serializes and deserializes objects so that they can be placed in ...
Python code Action Description index = file.keys() Index Fetch the stored keys list (an iterable view) found = 'key' in file Que ...
>>> dbase = shelve.open("mydbase") >>> object1 = ['The', 'bright', ('side', 'of'), ['life']] >>> obje ...
«
63
64
65
66
67
68
69
70
71
72
»
Free download pdf