Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should Python class filenames also be camelCased?

I know that classes in Python are typically cased using camelCase.

Is it also the normal convention to have the file that contains the class also be camelCase'd especially if the file only contains the class?

For example, should class className also be stored in className.py instead of class_name.py?

like image 413
m4jesticsun Avatar asked Feb 09 '17 03:02

m4jesticsun


People also ask

Do you capitalize Python file names?

PEP 8 recommends lowercase names for modules and packages. It makes no recommendations regarding filenames holding classes.


1 Answers

The following answer is largely sourced from this answer.

If you're going to follow PEP 8, you should stick to all-lowercase names, with optional underscores.

To quote PEP 8's naming conventions for packages & modules:

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability.

And for classes:

Class names should normally use the CapWords convention.

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

A Python module is simply a Python source file, which can expose classes, functions and global variables.

like image 119
Caitlin Quintero Weaver Avatar answered Sep 20 '22 04:09

Caitlin Quintero Weaver