【问题标题】:OrderedDict in IronPython missing?IronPython 中的 OrderedDict 丢失了吗?
【发布时间】:2013-10-14 22:40:18
【问题描述】:

为什么 OrderedDict 在 IronPython 中不可用:

import _collections as cl
dir(cl)

不显示 OrderedDict

【问题讨论】:

    标签: ironpython ordereddictionary


    【解决方案1】:

    在某些(大多数/全部?)实现中,OrderedDict 是公共 collections module 的一部分,而不是内部 _collections 的一部分。

    我扩展了您的 sn-p 以包含更多信息:

    import sys
    print(sys.version)
    import _collections as _cl
    print "_collections:", dir(_cl)
    import collections as cl
    print "collections:", dir(cl)
    

    对于 IronPython,结果是:

    2.7.4 (IronPython 2.7.4 (2.7.0.40) on .NET 4.0.30319.18331 (32-bit))
    _collections: ['__doc__', '__name__', '__package__', 'defaultdict', 'deque']
    collections: ['Callable', 'Container', 'Counter', 'Hashable', 'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'Mapping', 'MappingView', 'MutableMapping', 'MutableSequence', 'MutableSet', 'OrderedDict', 'Sequence', 'Set', 'Sized', 'ValuesView', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_abcoll', '_chain', '_get_ident', '_heapq', '_iskeyword', '_itemgetter', '_repeat', '_starmap', '_sys', 'defaultdict', 'deque', 'namedtuple']
    

    对于 CPython,结果是:

    2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]
    _collections: ['__doc__', '__name__', '__package__', 'defaultdict', 'deque']
    collections: ['Callable', 'Container', 'Counter', 'Hashable', 'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'Mapping', 'MappingView', 'MutableMapping', 'MutableSequence', 'MutableSet', 'OrderedDict', 'Sequence', 'Set', 'Sized', 'ValuesView', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_abcoll', '_chain', '_class_template', '_eq', '_field_template', '_get_ident', '_heapq', '_imap', '_iskeyword', '_itemgetter', '_repeat', '_repr_template', '_starmap', '_sys', 'defaultdict', 'deque', 'namedtuple']
    

    【讨论】: