Kodi Community Forum

Full Version: OrderedDict. How can I make an Ordered Dictionary?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can I make an Ordered Dictionary, is there a class I can import

"from collections import OrderedDict" doesn't seem to work with the python version used by Kodi,
are there any work around's.

Any ideas
Thanks
OrderedDict was added to the Standard Library in Python 2.7, while Kodi for some platforms uses Python 2.6. Download ordereddict module from the pip repository and add it to your plugin.
I downloaded ordereddict-1.1.tar.gz and put ordereddict.py in the root of the addon

import sys
import os
import OrderedDict

No error with import OrderedDict when run on Kodi

but when I add this
d = OrderedDict([('key1', 'value1'), ('key2', 'value2')])
I get an error.

I guess I'm not sure if I'm adding pip repository addordereddict module correctly,


Thanks
(2015-12-01, 19:15)1alpha Wrote: [ -> ]I get an error.

Whoop-de-doo, you got an error. But don't tell anyone WHAT error. That's a proprietary secret, right?
(2015-12-01, 21:43)Karnagious Wrote: [ -> ]
(2015-12-01, 19:15)1alpha Wrote: [ -> ]I get an error.

Whoop-de-doo, you got an error. But don't tell anyone WHAT error. That's a proprietary secret, right?

LOL
we will bump python to 2.7 across the board at the start of the v17 cycle, so ordered dict will be available soon.
(2015-12-01, 19:15)1alpha Wrote: [ -> ]but when I add this
d = OrderedDict([('key1', 'value1'), ('key2', 'value2')])
I get an error.

As others have said, without the actual error it's hard to know what's going on. That said, I'll take a stab in the dark. I have an addon that uses OrderedDict, and here's what I do:

to import (this should, in theory, automatically start using OrderedDict in Python 2.7 when available)
Code:
if sys.version_info >= (2, 7):
    from collections import OrderedDict as _ordereddict
else:
    from resources.common.ordereddict import OrderedDict as _ordereddict

Then later:
Code:
hashmap = _ordereddict()
#the next line is actually in a loop, not that it matters for the example)
hashmap[artist_hash] = artist_info['artist']

So I'm wondering if you're just not calling OrderedDict the right way.
(2015-12-01, 23:16)wsnipex Wrote: [ -> ]we will bump python to 2.7 across the board at the start of the v17 cycle, so ordered dict will be available soon.

That's awesome news!
Yeah, it's really great to hear!
(2015-12-01, 23:16)wsnipex Wrote: [ -> ]we will bump python to 2.7 across the board at the start of the v17 cycle, so ordered dict will be available soon.

2.7.0 or 2.7.10?
(2015-12-02, 03:49)Karnagious Wrote: [ -> ]
(2015-12-01, 23:16)wsnipex Wrote: [ -> ]we will bump python to 2.7 across the board at the start of the v17 cycle, so ordered dict will be available soon.

2.7.0 or 2.7.10?

2.7.10 for all platforms that use unified depends. Windows is on 2.7.9 already. I'll see if we can get it to 2.7.10 as well
https://github.com/xbmc/xbmc/pull/8207
(2015-12-01, 23:26)pkscout Wrote: [ -> ]So I'm wondering if you're just not calling OrderedDict the right way.

Thank you, OrderedDict works for me now

Code:
if sys.version_info >= (2,7): from collections import OrderedDict as _ordereddict
else: from ordereddict import OrderedDict as _ordereddict

d = _ordereddict([('key1', 'value1'), ('key2', 'value2')])