Python 3: Plist as OrderedDict

Gnarlodious gnarlodious at gmail.com
Tue Feb 9 11:07:42 EST 2010


On Feb 9, 12:15 am, Raymond Hettinger wrote:

> You may be able to monkey patch an OrderedDict into the PlistParser.
> Here's an untested stab at it:
>     from collections import OrderedDict
>     import plistlib
>     plistlib._InteralDict = OrderedDict


Genius! After fixing the misspelled InteralDict I got this:

from collections import OrderedDict
import plistlib
plistlib._InternalDict = OrderedDict
plistlib.readPlist('/path/to/some.plist')
--> OrderedDict([('List', 'of'), ('tuples', 'in'), ('plist',
'order')])

So thank you for that [somewhat contorted] solution.
To extract the list I am saying this:

ordered=plistlib.readPlist(path)
print(list(ordered))  # only a list of keys
print(ordered[list(ordered)[0]])

However this seems too laborious. is there an easier way?

-- Gnarlie




More information about the Python-list mailing list