Skip to content

Commit

Permalink
pythongh-101992: update pstlib module documentation (pythonGH-102133)
Browse files Browse the repository at this point in the history
(cherry picked from commit e4609cb)

Co-authored-by: Dustin Rodrigues <[email protected]>
  • Loading branch information
dtrodrigues authored and miss-islington committed Mar 4, 2023
1 parent 925ebfb commit 6680039
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions Lib/plistlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,38 @@
Generate Plist example:
import datetime
import plistlib
pl = dict(
aString = "Doodah",
aList = ["A", "B", 12, 32.1, [1, 2, 3]],
aFloat = 0.1,
anInt = 728,
aDict = dict(
anotherString = "<hello & hi there!>",
aUnicodeValue = "M\xe4ssig, Ma\xdf",
aThirdString = "M\xe4ssig, Ma\xdf",
aTrueValue = True,
aFalseValue = False,
),
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)
print(plistlib.dumps(pl).decode())
Parse Plist example:
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"])
"""
__all__ = [
"InvalidFileException", "FMT_XML", "FMT_BINARY", "load", "dump", "loads", "dumps", "UID"
Expand Down

0 comments on commit 6680039

Please sign in to comment.