summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDustin Rodrigues <dust.rod@gmail.com>2023-02-17 19:30:29 (GMT)
committerGitHub <noreply@github.com>2023-02-17 19:30:29 (GMT)
commita1723caabfcdca5d675c4cb04554fb04c7edf601 (patch)
tree9943432378a1a6ba82534d8121431156204d1655
parentf482ade4c7887c49dfd8bba3be76f839e562608d (diff)
downloadcpython-a1723caabfcdca5d675c4cb04554fb04c7edf601.zip
cpython-a1723caabfcdca5d675c4cb04554fb04c7edf601.tar.gz
cpython-a1723caabfcdca5d675c4cb04554fb04c7edf601.tar.bz2
gh-101992: update plistlib examples to be runnable (#101994)
* gh-101992: update plistlib examples to be runnable * Update Doc/library/plistlib.rst --------- Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
-rw-r--r--Doc/library/plistlib.rst21
1 files changed, 15 insertions, 6 deletions
diff --git a/Doc/library/plistlib.rst b/Doc/library/plistlib.rst
index 5ded966..7aad15e 100644
--- a/Doc/library/plistlib.rst
+++ b/Doc/library/plistlib.rst
@@ -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]],
@@ -172,13 +175,19 @@ 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)
+ print(plistlib.dumps(pl).decode())
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"])