[Python-checkins] gh-101992: update pstlib module documentation (GH-102133)
miss-islington
webhook-mailer at python.org
Sun Mar 5 01:36:19 EST 2023
https://github.com/python/cpython/commit/f96907a67ca1e21455fcec09447f0ffcc2dc1243
commit: f96907a67ca1e21455fcec09447f0ffcc2dc1243
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2023-03-04T22:36:00-08:00
summary:
gh-101992: update pstlib module documentation (GH-102133)
(cherry picked from commit e4609cbe4ca2d3d4fc07c19a7d0bdec52f054c63)
Co-authored-by: Dustin Rodrigues <dust.rod at gmail.com>
files:
M Lib/plistlib.py
diff --git a/Lib/plistlib.py b/Lib/plistlib.py
index 664890d25252..53e718f063b3 100644
--- a/Lib/plistlib.py
+++ b/Lib/plistlib.py
@@ -21,6 +21,9 @@
Generate Plist example:
+ import datetime
+ import plistlib
+
pl = dict(
aString = "Doodah",
aList = ["A", "B", 12, 32.1, [1, 2, 3]],
@@ -28,22 +31,28 @@
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"
More information about the Python-checkins
mailing list