Python Data Persistence – plistlib Module

Python Data Persistence – plistlib Module

Lastly, we have a look at plist module that used to read and write ‘property list’ files (they usually have .plist’ extension). This type of file is mainly used by MAC OS X. These files are essentially XML documents, typically used to store and retrieves properties of an object.
The functionality of plastic module is more or less similar to other serialization libraries. It defines dumps () and loads () functions for the string representation of Python objects. The load () and dump () functions read and write plist disk files.
The following script stores a diet object to a plist file.

Example

import plistlib
proplist = {
"name" : "Ramesh",
"class":"XII",
"div":"B",
"marks" : {"phy":50, "che" 60, "maths":80}
}
fileName=open ('marks .plist' ' wb' )
plistlib . dump (proplist, fileName)
fileName . close ()

The load() function retrieves an identical dictionary object from the file.

Example

with open('marks.plist', 'rb') as fp:
p1 = plistlib.load(fp) 
print(p1)

Another important data persistence library in Python is the sqlite3 module. It deals with read/write operations on the SQLite relational database. Before we explore its functionality, let us get acquainted with RDBMS concepts and the basics of SQL, which is the next chapter.