Skip to content

Commit a1723ca

Browse files
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 <[email protected]>
1 parent f482ade commit a1723ca

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Diff for: Doc/library/plistlib.rst

+15-6
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ Examples
159159

160160
Generating a plist::
161161

162+
import datetime
163+
import plistlib
164+
162165
pl = dict(
163166
aString = "Doodah",
164167
aList = ["A", "B", 12, 32.1, [1, 2, 3]],
@@ -172,13 +175,19 @@ Generating a plist::
172175
),
173176
someData = b"<binary gunk>",
174177
someMoreData = b"<lots of binary gunk>" * 10,
175-
aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
178+
aDate = datetime.datetime.now()
176179
)
177-
with open(fileName, 'wb') as fp:
178-
dump(pl, fp)
180+
print(plistlib.dumps(pl).decode())
179181

180182
Parsing a plist::
181183

182-
with open(fileName, 'rb') as fp:
183-
pl = load(fp)
184-
print(pl["aKey"])
184+
import plistlib
185+
186+
plist = b"""<plist version="1.0">
187+
<dict>
188+
<key>foo</key>
189+
<string>bar</string>
190+
</dict>
191+
</plist>"""
192+
pl = plistlib.loads(plist)
193+
print(pl["foo"])

0 commit comments

Comments
 (0)