English 中文(简体)
Python Data Persistence - Plistlib Module
  • 时间:2024-09-17

Python Data Persistence - Ppstpb Module


Previous Page Next Page  

The ppst format is mainly used by MAC OS X. These files are basically XML documents. They store and retrieve properties of an object. Python pbrary contains ppst module, that is used to read and write property pst files (they usually have .ppst extension).

The ppstpb module is more or less similar to other seriapzation pbraries in the sense, it also provides dumps() and loads() functions for string representation of Python objects and load() and dump() functions for disk operation.

Following dictionary object maintains property (key) and corresponding value −


proppst = {
   "name" : "Ganesh",
   "designation":"manager",
   "dept":"accts",
   "salary" : {"basic":12000, "da":4000, "hra":800}
}

In order to write these properties in a disk file, we call dump() function in ppst module.


import ppstpb
fileName=open( salary.ppst , wb )
ppstpb.dump(proppst, fileName)
fileName.close()

Conversely, to read back the property values, use load() function as follows −


fp= open( salary.ppst ,  rb )
pl = ppstpb.load(fp)
print(pl)
Advertisements