summaryrefslogtreecommitdiffstats
path: root/Lib/plistlib.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-03-05 06:36:07 (GMT)
committerGitHub <noreply@github.com>2023-03-05 06:36:07 (GMT)
commitd4992c7315c1b92a73eec30407ed0cf3b673194a (patch)
tree302fe8a8a823bc8752e01f7321df8def5359be59 /Lib/plistlib.py
parent925ebfbfd22ac2ba3315ff427b9739d1e1907664 (diff)
downloadcpython-d4992c7315c1b92a73eec30407ed0cf3b673194a.zip
cpython-d4992c7315c1b92a73eec30407ed0cf3b673194a.tar.gz
cpython-d4992c7315c1b92a73eec30407ed0cf3b673194a.tar.bz2
gh-101992: update pstlib module documentation (GH-102133)
(cherry picked from commit e4609cbe4ca2d3d4fc07c19a7d0bdec52f054c63) Co-authored-by: Dustin Rodrigues <dust.rod@gmail.com>
Diffstat (limited to 'Lib/plistlib.py')
-rw-r--r--Lib/plistlib.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/Lib/plistlib.py b/Lib/plistlib.py
index bc8e4c8..d6c997e 100644
--- a/Lib/plistlib.py
+++ b/Lib/plistlib.py
@@ -21,6 +21,9 @@ datetime.datetime objects.
Generate Plist example:
+ import datetime
+ import plistlib
+
pl = dict(
aString = "Doodah",
aList = ["A", "B", 12, 32.1, [1, 2, 3]],
@@ -28,22 +31,28 @@ Generate Plist example:
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"