看一下source code,似乎唯一的“原因”是OrderedDict
是用Python编写的,而{
有人能提供更好的解释吗?我希望有更好的理由。在
编辑:
alleged duplicate的答案对于python2.7是可以的,而对于没有类/类型区别的python3则不行。OrderedDict
和{
>>> collections.defaultdict
<class 'collections.defaultdict'>
>>> collections.OrderedDict
<class 'collections.OrderedDict'>
根据我在python开发人员档案中发现的情况,这只是开发人员没有遵循自己的指导方针的一个例子。在
在讨论引入} to ^{} 来修复这种不一致性:
OrderedDict
的政治公众人物时,Guido实际上建议renaming ^{请注意,} :
NamedDict
是一个打字错误,he meant ^{我不确定为什么这个更改(以及其他模块的类似更改,例如
socket.socket
,datetime.datetime
)从未进行过,因为Guido支持这样做。在具有讽刺意味的是,it was Guido(或者可能是Alex Martelli)想出了这个名字
defaultdict
,尽管他们是基于Google使用的一个名为DefaultDict
的内部类:讨论很快从
defaultdict
变成了它是collections
模块的一部分,但是所有小写的名称都被保留了。这个讨论发生在2006年,所以PEP8在那时已经存在很多年了。不知道为什么当时没有人想到它应该被命名为DefaultDict
。在相关问题 更多 >
编程相关推荐