

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Generate and parse Mac OS X .plist files using Python (plistlib)
Files with '.plist' the extension is used by Mac OS X applications to store application properties. The plislib module provides an interface to read/write operations of these property list files.
The plist file format serializes basic object types, like dictionaries, lists, numbers, and strings. Usually, the top level object is a dictionary. To write out and to parse a plist file, use the dump() and load() functions. Serialized byte strings are handled by use dumps() and loads() functions. Values can be strings, integers, floats, booleans, tuples, lists, dictionaries (but only with string keys).
This module defines the following functions −
load() | Read a plist file pointed by readable and binary file object. format of the file and the following values are valid
|
dump() | Write value to a plist file refereed by writable, binary file object. The fmt argument specifies the format of the plist file and can be one of the following values
|
loads() | Load a plist from a bytes object. See load() for an explanation of the keyword arguments. |
dumps() | Return value as a plist-formatted bytes object. See the documentation for dump() for an explanation of the keyword arguments of this function. |
Following script stores serialized dictionary in plist file
import plistlib properties = { "name" : "Ramesh", "College":"ABC College", "Class":"FY", "marks" : {"phy":60, "che":60, "maths":60} } fileName=open('prpos.plist','wb') plistlib.dump(pl, fileName) fileName.close()
To read plist file use load() function
with open('marks.plist', 'rb') as fp: pl = plistlib.load(fp) print(pl)
- Related Questions & Answers
- Mac OS X Structure
- Installing Python on Mac OS
- Generate temporary files and directories using Python
- Differentiate between OS and DBMS files and OS and DBMS buffer manager
- What languages have been used to write Windows, Mac OS and Linux OS?
- How to compile and execute C# programs on Mac OS?
- How to set Java Path in Mac OS?
- How to install Selenium WebDriver on Mac OS?
- Extracting MAC address using Python
- How to set JAVA_HOME for Java in Mac OS?
- Recommended IDEs for C# on Windows/Linux/Mac OS
- How to get empty files in Windows OS using PowerShell?
- How to read and parse CSV files in C++?
- How to parse JSON files in Golang?
- Encode and decode uuencode files using Python