| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f4f5dd5 commit b615678
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -159,6 +159,9 @@ Examples | |||
| 159 | 159 | ||
| 160 | 160 | Generating a plist:: | |
| 161 | 161 | ||
| 162 | + import datetime | ||
| 163 | + import plistlib | ||
| 164 | + | ||
| 162 | 165 | pl = dict( | |
| 163 | 166 | aString = "Doodah", | |
| 164 | 167 | aList = ["A", "B", 12, 32.1, [1, 2, 3]], | |
@@ -172,13 +175,19 @@ Generating a plist:: | |||
| 172 | 175 | ), | |
| 173 | 176 | someData = b"<binary gunk>", | |
| 174 | 177 | someMoreData = b"<lots of binary gunk>" * 10, | |
| 175 | - aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())), | ||
| 178 | + aDate = datetime.datetime.now() | ||
| 176 | 179 | ) | |
| 177 | - with open(fileName, 'wb') as fp: | ||
| 178 | - dump(pl, fp) | ||
| 180 | + print(plistlib.dumps(pl).decode()) | ||
| 179 | 181 | ||
| 180 | 182 | Parsing a plist:: | |
| 181 | 183 | ||
| 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"]) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments