为什么 OrderedDict 在 IronPython 中不可用:
import _collections as cl
dir(cl)
不显示 OrderedDict
为什么 OrderedDict 在 IronPython 中不可用:
import _collections as cl
dir(cl)
不显示 OrderedDict
在某些(大多数/全部?)实现中,OrderedDict 是公共集合模块的一部分,而不是内部_collections的一部分。
我扩展了您的代码段以包含更多信息:
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']