Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming convention for containers in the Python standard library

Consider the naming convention used for different types of containers in the Python standard library:

Why do some methods follow camel case, but others like deque and defaultdict don't? How are these methods different from each other in a way that would explain this difference?

If it's because at some point the convention changed, why wouldn't the module e.g. provide alias them with camel case names to old names as well?

like image 840
Josh Avatar asked Jul 19 '20 21:07

Josh


People also ask

What is the standard file naming convention in Python?

modules (filenames) should have short, all-lowercase names, and they can contain underscores; packages (directories) should have short, all-lowercase names, preferably without underscores; classes should use the CapWords convention.

What is the best practice naming convention for Python?

In Python, the names of variables and functions should be lowercase. Individual words can be separated by underscores when needed. This will improve readability within your code. Method names should follow the same conventions as function names.


1 Answers

Usually in python, class names follow the "pascal" case convention, methods / functions follow the "snake" case convention. But here is a official reference from https://www.python.org/dev/peps/pep-0008/:

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.

When an extension module written in C or C++ has an accompanying Python module that provides a higher level (e.g. more object oriented) interface, the C/C++ module has a leading underscore (e.g. _socket).

Class names

Class names should normally use the CapWords convention.

The naming convention for functions may be used instead in cases where the interface is documented and used primarily as a callable.

Note that there is a separate convention for builtin names: most builtin names are single words (or two words run together), with the CapWords convention used only for exception names and builtin constants.

like image 115
Michael Avatar answered Oct 18 '22 05:10

Michael