Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Significance of Capitalization in Python collections module?

Is there any significance to the capitalization practices for classes in the collections module in Python? In particular, I find it puzzling that OrderedDict uses CamelCase while defaultdict is all lowercase. My assumption would be they would all use CamelCase since they are all classes.

enter image description here

like image 569
willk Avatar asked Jul 23 '19 14:07

willk


People also ask

Do you capitalize Python?

First, Python is a programming language with a defined syntax and specification. When referring to the language, we will capitalize the name as "Python".

How do you name a Python module?

Package and Module Names Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.

Is CamelCase used in Python?

You'll see camelCase in some really old Python code but it's not the modern convention at all. Write your code according to the conventions so other Python developers will know what kind of construct they're dealing with when reading your code.


1 Answers

The naming is historical (for CPython). Originally, CamelCase classes (like OrderedDict) were pure python implemented and other classes (like defaultdict) were C-implemented. However, now the names are just legacy (mostly), since C-implementation has often been added (e.g. here for OrderedDict- you can see now that the python implementation is only a fallback).

like image 151
Chris_Rands Avatar answered Nov 04 '22 09:11

Chris_Rands