Python 3: Plist as OrderedDict

Benjamin Kaplan benjamin.kaplan at case.edu
Mon Feb 8 23:21:13 EST 2010


On Mon, Feb 8, 2010 at 11:02 PM, Gnarlodious <gnarlodious at gmail.com> wrote:
> I am trying to read a *.plist into Python 3's OrderedDict but can't
> figure it out. Saying something like this:
>
> from plistlib import readPlist
> dict=readPlist('/path/file.plist')
> --> arbitrarily ordered dictionary compared to the XML file
>
> from collections import OrderedDict
> OrderedDict(readPlist('/path/file.plist'))
> --> essentially does the same thing as the previous
> readPlist seems to do the scrambling, is this a non-implementation in
> Python 3.1?
>
> I "upgraded" to Py3 to have OrderedDict, so please don't say it is
> impossible...
>
> -- Gnarlie

readPlist returns a dict. That dict is unordered. Wrapping the call in
OrderedDict() doesn't suddenly make readPlist use an ordered dict
instead, it just takes the (unordered) dict and sticks it in a new
OrderedDict. I suppose you could dig into the plistlib source code and
change that to use the OrderedDict if you really need it.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list