Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a1723ca

Browse filesBrowse 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 <tjreedy@udel.edu>
1 parent f482ade commit a1723ca
Copy full SHA for a1723ca

File tree

Expand file treeCollapse file tree

1 file changed

+15
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-6
lines changed

‎Doc/library/plistlib.rst

Copy file name to clipboardExpand all lines: Doc/library/plistlib.rst
+15-6Lines changed: 15 additions & 6 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.