Should Python class file names also be camelCased?

I know that classes in Python are usually cropped using camelCase.

Is it also a normal convention that the file containing the class is also camelCase'd, especially if the file contains only the class?

For example, if the class className also stored in className.py instead of class_name.py ?

+6
source share
2 answers

The following answer is mainly derived from this answer .

If you intend to follow PEP 8, you must follow all lowercase names with extra underscores.

To quote the PEP 8 naming conventions for packages and modules :

Modules must have short, all lowercase names. Underscores can be used in the module name if this improves readability.

And for classes:

Class names should usually use the CapWords convention.

See this answer for the difference between module, class and package:

The Python module is just a Python source file that can expose classes, functions, and global variables.

+5
source

My question is, is there a normal convention to have a file that contains a class also camelCase'd, especially if the file only contains a class

Short answer: None.

Longer answer: there should be all lower case and underscores as needed.

From PEP8 "Package and Module Names" :

Modules must have short, all lowercase names. Underscores can be used in a module name if it improves readability. Python packages should also have short uppercase names, although using underscores is not recommended.

If you do not know what module is :

A module is a file containing Python definitions and instructions. file name is the name of the module with the suffix .py added.

+2
source

Source: https://habr.com/ru/post/1014824/


All Articles