Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions Doc/library/plistlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ Examples

Generating a plist::

import datetime
import plistlib

pl = dict(
aString = "Doodah",
aList = ["A", "B", 12, 32.1, [1, 2, 3]],
Expand All @@ -172,13 +175,20 @@ Generating a plist::
),
someData = b"<binary gunk>",
someMoreData = b"<lots of binary gunk>" * 10,
aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
aDate = datetime.datetime.now()
)
with open(fileName, 'wb') as fp:
dump(pl, fp)
with open("blah.plist", 'wb') as fp:
plistlib.dump(pl, fp)

Parsing a plist::

with open(fileName, 'rb') as fp:
pl = load(fp)
print(pl["aKey"])
import plistlib

plist = b"""<plist version="1.0">
<dict>
<key>foo</key>
<string>bar</string>
</dict>
</plist>"""
pl = plistlib.loads(plist)
print(pl["foo"])