diff options
author | Dustin Rodrigues <dust.rod@gmail.com> | 2023-03-04 21:35:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-04 21:35:25 (GMT) |
commit | e4609cbe4ca2d3d4fc07c19a7d0bdec52f054c63 (patch) | |
tree | 6df6c312f46103d7d09d419344f5dfe859e164ec /Lib/plistlib.py | |
parent | 81763341ede99ea5ae8993a57b8e3b71b46b2d72 (diff) | |
download | cpython-e4609cbe4ca2d3d4fc07c19a7d0bdec52f054c63.zip cpython-e4609cbe4ca2d3d4fc07c19a7d0bdec52f054c63.tar.gz cpython-e4609cbe4ca2d3d4fc07c19a7d0bdec52f054c63.tar.bz2 |
gh-101992: update pstlib module documentation (#102133)
Diffstat (limited to 'Lib/plistlib.py')
-rw-r--r-- | Lib/plistlib.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/Lib/plistlib.py b/Lib/plistlib.py index 30f3f67..3292c30 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" |