mirror of
https://github.com/python/cpython.git
synced 2025-10-02 13:22:19 +00:00
gh-101992: update pstlib module documentation (GH-102133)
(cherry picked from commit e4609cbe4c
)
Co-authored-by: Dustin Rodrigues <dust.rod@gmail.com>
This commit is contained in:
parent
cda1d52ab8
commit
f96907a67c
1 changed files with 16 additions and 7 deletions
|
@ -21,6 +21,9 @@ datetime.datetime objects.
|
||||||
|
|
||||||
Generate Plist example:
|
Generate Plist example:
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
import plistlib
|
||||||
|
|
||||||
pl = dict(
|
pl = dict(
|
||||||
aString = "Doodah",
|
aString = "Doodah",
|
||||||
aList = ["A", "B", 12, 32.1, [1, 2, 3]],
|
aList = ["A", "B", 12, 32.1, [1, 2, 3]],
|
||||||
|
@ -28,22 +31,28 @@ Generate Plist example:
|
||||||
anInt = 728,
|
anInt = 728,
|
||||||
aDict = dict(
|
aDict = dict(
|
||||||
anotherString = "<hello & hi there!>",
|
anotherString = "<hello & hi there!>",
|
||||||
aUnicodeValue = "M\xe4ssig, Ma\xdf",
|
aThirdString = "M\xe4ssig, Ma\xdf",
|
||||||
aTrueValue = True,
|
aTrueValue = True,
|
||||||
aFalseValue = False,
|
aFalseValue = False,
|
||||||
),
|
),
|
||||||
someData = b"<binary gunk>",
|
someData = b"<binary gunk>",
|
||||||
someMoreData = b"<lots of binary gunk>" * 10,
|
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:
|
print(plistlib.dumps(pl).decode())
|
||||||
dump(pl, fp)
|
|
||||||
|
|
||||||
Parse Plist example:
|
Parse Plist example:
|
||||||
|
|
||||||
with open(fileName, 'rb') as fp:
|
import plistlib
|
||||||
pl = load(fp)
|
|
||||||
print(pl["aKey"])
|
plist = b'''<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>foo</key>
|
||||||
|
<string>bar</string>
|
||||||
|
</dict>
|
||||||
|
</plist>'''
|
||||||
|
pl = plistlib.loads(plist)
|
||||||
|
print(pl["foo"])
|
||||||
"""
|
"""
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"InvalidFileException", "FMT_XML", "FMT_BINARY", "load", "dump", "loads", "dumps", "UID"
|
"InvalidFileException", "FMT_XML", "FMT_BINARY", "load", "dump", "loads", "dumps", "UID"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue