views:

53

answers:

3

Why do collection.defaultdict and collection.OrderedDict have different capitalizations?

Is there some subtle difference that I should be aware of?

(P3K)

+1  A: 

Usually, that is in accordance with good style, classes are capitalised.

def MyClass (object):
    pass

my_instance = MyClass()

like this.

You should read this document about it: http://www.python.org/dev/peps/pep-0008/

stefano palazzo
Then the question is, why is this not the case for `defaultdict`?
Space_C0wb0y
Uhm. Good Question. :-) I think it may be to be consistent with its parent class, dict. dict is one of the built in types and, as such, lowercase (str, int, ...). May be the authors wanted to keep open the option to introduce defaultdict to the built in namespace, alongside dict. In which case, **breaking the rules** (cf. PEP8) would make sense.
stefano palazzo
`OrderedDict` is also a subclass of `dict`, and it's capitalized properly. As to converting `defaultdict` into a built-in class, why not convert the capitalization at the same time? By that token, any new class in Python libraries should be written in lowercase, in case it might one day become a builtin.
max
*singularity* finally explained it properly, makes absolute sense.
stefano palazzo
+1  A: 

defaultdict is written in C and pep8 don't apply , in the other hand OrderDict is written in python,

you can read C code norm for the C implementation of Python here : PEP 7

reference : source code python2.7

defaultdict  : Modules/_collectionsmodule.c
OrderDict : Lib/collections.py
singularity
Why can't the C class be exposed to Python library in capitalized case? C is case-sensitive. What am I missing?
max
@max: every language has his norm of coding , we can't code in C using python norm pep8 right ? here is the norm for C extention : http://www.python.org/dev/peps/pep-0007/
singularity
I agree in general... but when writing a function in C for the sole purpose of providing a library function for Python's standard library, I'd follow Python style for the function name
max
+1  A: 

The capitalization of the class names is irrelevant, it doesn't signify anything. Except that Python has sometimes grown organically and the standard library doesn't have the same homogenous feel as other large libraries such as the Win32 API or the Java standard library.

Ned Batchelder