小文字とアッパーキャメルケースが混在しているのはなぜですか?
namedtuple
deque
Counter
OrderedDict
defaultdict
なぜcollections代わりにCollections?
たとえば、私は時々これを行います:
from collections import default_dict
間違って。将来このような間違いを避けるために、どのような経験則を使用できますか?
小文字とアッパーキャメルケースが混在しているのはなぜですか?
namedtuple
deque
Counter
OrderedDict
defaultdict
なぜcollections代わりにCollections?
たとえば、私は時々これを行います:
from collections import default_dict
間違って。将来このような間違いを避けるために、どのような経験則を使用できますか?
collections モジュールはPEP 8 Style Guideに従います:
モジュールには、すべて小文字の短い名前を付ける必要があります。
これが理由ですcollections
ほとんど例外なく、クラス名は CapWords 規則を使用します。
両方のクラスであるため、これがCounterandである理由です。OrderedDict
>>> collections.Counter
<class 'collections.Counter'>
>>> collections.OrderedDict
<class 'collections.OrderedDict'>
namedtupleは関数であるため、上記のスタイル ガイドには従いません。dequeおよびdefaultdicts は型であるため、次のことも行いません。
>>> collections.deque
<type 'collections.deque'>
>>> collections.namedtuple
<function namedtuple at 0x10070f140>
>>> collections.defaultdict
<type 'collections.defaultdict'>
注: Python 3.5 では、defaultdict と deque もクラスになりました。
>>> import collections
>>> collections.Counter
<class 'collections.Counter'>
>>> collections.OrderedDict
<class 'collections.OrderedDict'>
>>> collections.defaultdict
<class 'collections.defaultdict'>
>>> collections.deque
<class 'collections.deque'>
下位互換性のために小文字を保持しているdefaultdictと思います。dequeスタイル ガイドのために、このような大幅な名前の変更を行うとは思いません。